Written by Allen Wyatt (last updated September 23, 2022)
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.
Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!
You can open multiple documents at the same time in Word, and each document occupies its own document window. Here's a ...
Discover MoreNeed to figure out the number of characters in a range of selected text? Here's how to do it in VBA.
Discover MoreNeed to have your macro copy a file from one place to another? It's easy to do using the FileCopy command, described in ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
2021-09-30 02:32:25
Anomander Rake
of just type:
InSelection = (Selection.Type = wdSelectionIP)
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 © 2024 Sharon Parq Associates, Inc.
Comments