Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Checking for a Text Selection Length.
by Allen Wyatt
(last updated June 9, 2018)
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 Selection.Type=wdSelectionIP Then Inselection=True End If
Or, If you prefer:
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (12175) applies to Microsoft Word 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Word here: Checking for a Text Selection Length.
Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!
Word is very dynamic in how it "flows" text from one line to another and one page to another. In most cases we are ...Discover More
Macros are often used to process documents. If part of the processing involves making text selections uppercase, Word ...Discover More
One of the math functions you can use in your macros is the Int function. It provides a way for you to derive an integer ...Discover More
Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.