Welcome toWord.Tips.Net
Ask a Word Question
Make a Comment
Learn Access Now
Free Printable Forms
Beauty Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Legal Tips
Money Tips
Organizing Tips
Pest Tips
Pet Tips
Wedding Tips
Word2007 Tips
WordTips
Collapsing and Expanding Subdocuments
There are numerous times when you are writing macros when you will need to determine if the user has made a selection. There are numerous ways you can do this in a macro. The following code illustrates one possible method for accomplishing this in VBA. It sets the value of a flag, InSelection, to True if there is currently a selection. Otherwise InSelection is set to False.
InSelection = False If Len(Selection) > 0 Then InSelection = True
The technique used here relies on the fact that if a selection has been made, it will have a length. This length is returned by the Len function of VBA.
Tip #740 applies to Microsoft Word versions: 97 2000 2002 2003 2007
Save Time! WordTips has been published weekly since early 1997. Past issues are available in convenient WordTips archives. Have your own enhanced archive of WordTips at your fingertips, available to use at any time!