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!
Word makes it easy to insert today's date in a document, but not as easy to insert a date X number of days in the future. ...
Discover MoreBookmarks can be very handy in a document. Word provides a VBA command you can use to easily select any of those bookmarks.
Discover MoreWhen working with macros, you may want to create a variable that will remain constant from one instance of the macro to ...
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 © 2025 Sharon Parq Associates, Inc.
Comments