Written by Allen Wyatt (last updated November 29, 2025)
This tip applies to Word 97, 2000, 2002, and 2003
There are numerous times when you are writing macros when you will need to determine if the user has made a selection. The following VBA code will let you know if a selection has been made. The variable designated to be a flag (InSelection) is first set to False, and then the Type property of the Selection object is used to determine if there is a selection. If so, then InSelection is set to True.
InSelection = False If Selection.Type = wdSelectionIP Then InSelection = True
Note:
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (127) applies to Microsoft Word 97, 2000, 2002, and 2003.
Do More in Less Time! An easy-to-understand guide to the more advanced features available in the Microsoft 365 version of Word. Enhance the quality of your documents and boost productivity in any field with this in-depth resource. Complete your Word-related tasks more efficiently as you unlock lesser-known tools and learn to quickly access the features you need. Check out Microsoft 365 Word For Professionals For Dummies today!
Need to know if the Num Lock key is on or off? You can use a short bit of macro code to figure out the state of the key.
Discover MoreWhen comparing two pieces of text, you may find that Word's smart quotes can mess up the comparison. Here's a quick way ...
Discover MoreNeed to process a document, paragraph by paragraph, in a macro? It's easy to do once you understand that Word's object ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
2025-12-01 05:20:05
Steve Wells
I often write tools that process the selected chunk of text, but if nothing is selected, I process the whole document.
The relevant portion of my code usually looks something like this:
' Just an insertion point or a text selection?
With Application.Selection
If .Type = wdSelectionIP Then ' Just an insertion point
.WholeStory ' Include the whole document
.HomeKey wdStory ' Move start to the beginning
.EndKey Unit:=wdStory, Extend:=wdExtend ' End at the story end
End If
' [Process the selected chunk of text or the (formerly no) text around the selection point expanded to include the whole document]
End With
Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon interface.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments