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.
Discover the Power of Microsoft Office This beginner-friendly guide reveals the expert tips and strategies you need to skyrocket your productivity and use Office 365 like a pro. Mastering software like Word, Excel, and PowerPoint is essential to be more efficient and advance your career. Simple lessons guide you through every step, providing the knowledge you need to get started. Check out Microsoft Office 365 For Beginners today!
Using a macro to format your document (or portions of your document) is not all that uncommon. If you want your macro to ...
Discover MoreWhen working with documents in a macro, it makes sense that you may need to create a document from time to time. Here's ...
Discover MoreNeed to figure out the hour represented by a particular time value? It's easy to do in a macro; just use the Hour ...
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