Heading

This is some text inside of a div block.
This is some text inside of a div block.
This is some text inside of a div block.
min read

Selection types with text

Word • Macros • Basics
Peter Ronhovde
18
min read

We introduce various selection types in general Word documents focusing on text selections for writing and editing macros. Understanding selection types will allow us to make appropriate decisions when a macro runs, so we can create safer, more functional macros.

Thanks for your interest

This content is part of a paid plan.

Detecting the Selection Type

For many writing and editing macros, we want to take different actions depending on whether a selection already exists in the document when the macro runs. We might we run an extra macro step, skip a step, or just do different subtasks in either case.

What is the Selection?

The selection (with a lowercase s) is the little gray box we see on the screen after we drag the mouse cursor across some text. Various selection types exist in Word. While some of them are more useful in non-fiction documents, the most important case for many writers is just detecting whether a normal, everyday text selection exists in the document or not.

To create a functioning macro, VBA must have some way of interacting with the selection in a document.

Selection in VBA

In Word VBA, the Selection (with a capital S) is how VBA internally represents the selection or insertion point we see and manipulate on the screen. It is a virtual (in the everyday sense) object that encapsulates what we can do with it in a document. As an object, it defines many actions (called "methods") and data (called "properties") that allow us to control it and the associated document content. Given its purpose, only one Selection exists in each open document. A separate article covers the Selection in more detail as VBA implements it for Word.

Typical selection test

How do we detect a selection in a document in a macro? A rough conditional statement to test what type of selection exists in a Word document might be something like:

' Conditional statement to detect whether an initial selection exists
If a selection exists in the document then
' Initial selection exists, so do something important with it ...
Otherwise (not a real VBA keyword)
' No selection exists, so do something else important (optional) ...
End the selection check

Unfortunately, we encounter a practical problem when translating this statement into VBA based on how it interprets different types of selections, so we need to distinguish between them in a macro.

Selection categories

Word includes several general selection categories:

  • No selection meaning an insertion point is present in the document
  • Normal selection (but the practical definition is vague)
  • Non-contiguous selections where the user selects multiple, usually disconnected regions of content
  • Block selection where a rectangle of text, often cutting across paragraph lines, is selected
  • Table selection where all or part of a table is selected beyond just some text inside a cell
  • Shape selection when only a shape is selected
  • Frame selection when only a frame is selected

Unfortunately, the boundaries between the different types are not as clear as we would prefer when creating macros. This makes our VBA macro experience more difficult at times since we need to be aware of the possible gotchas and how to distinguish between them.

For one, VBA doesn't play nice with non-contiguous or block selections, so we won't work much with them in our macros. We will not often use shapes, tables, or frames; so we'll focus on normal or no selections. Toward that goal, we need to understand what Word considers to be a normal selection. We'll leverage this information below to create a skeleton for a selection-based decision in a macro.

What is a normal selection?

Does life exist on other planets? What is dark matter? What is a normal selection in Word? All mysteries of the universe …

Presumably, a "normal" selection would be a typical text selection in Word which is exactly what we want … and it is, kind of, but not really. We'll get into some of the gritty details below, but be aware of the caveats if you work with more complicated documents.

What are some of the discrepancies?

Issues with a normal selection

A normal selection can be ambiguous in a general Word document. Roughly speaking, shapes, tables, and other non-text elements can cause problems in a text-oriented editing macro. Novel writers a less likely to include shapes, tables, or images in documents; but non-fiction writers may use more of them.

Selections that meet any of the following criteria will register as a normal Selection Type. The list is not exhaustive.

Text selection

Only text is selected or no document content is selected. This is the typical, normal selection we are interested in detecting and using in a writing and editing macro.

Text inside shapes or tables

Selected text may be inside a shape that allows text. As long as the shape itself is not selected, it will still count as a normal selection. Selected text may also be inside a table as long as the table or a full cell, row, or column is not included in the selection. These cases may work with some editing macros because the text is entirely inside the shape or a table cell.

Full element selections

If a whole shape, table, or frame is included in a selection along with some regular document text outside the element, the selection will still be identified as a normal selection. Generally speaking, such selections could cause problems in an editing macro if the logic assumes only text in a selection.

Non-contiguous selections

Non-contiguous selections (not block selections) register as a normal selection. While some macros may work with them by default, VBA doesn't currently give us the proper tools to work with them at any level of detail.

How do we detect the Selection Type?

Enough with the descriptions and chatter. How do we specifically check the type of the selection in VBA to make decisions in our writing and editing macros?

The Selection's Type property stores different values depending on what content, if any, is currently selected in the document. The Type property is stored as a number from a specific table of type constants, but the descriptions are rather terse. The table values obviously include our focus of detecting whether or not any text is selected in the document, but the details are a little troublesome.

For our purposes when creating writing and editing macros that manipulate text, the most important Type constants are:

  • wdSelectionNormal is a regular document selection as Word defines it
  • wdSelectionIP corresponds to “no selection” in the intuitive sense when no text or other objects (e.g., shape, picture, etc.) are selected in the document. The cursor is an insertion point waiting for us to type something.

The Type property is internally updated by Word as selections are made, cancelled, deleted, etc. The other type constants relate to special case selections which we will largely ignore unless a particular need arises.

Typical selection type conditions

Since the Selection's Type is just a number, we can directly compare it to any of the possible type constants. A typical condition to test for a "normal" selection would be:

' Selection Type condition for a normal selection
Selection.Type = wdSelectionNormal ' But we have a problem ...

While this looks like assigning a number to the Type property with the equals = sign, VBA will interpret it as a True or False (Boolean) value when it's used in a conditional statement or anywhere else a Boolean value is expected.

Normal selection conditional statement

In principle, we would use this condition in the above rough conditional statement to check whether the current document selection is normal. We would then take an appropriate action either way. The VBA test for a normal selection would be:

' Normal selection type is overly general (not recommended)
If Selection.Type = wdSelectionNormal Then
' A normal selection exists, so do something important ...
Else
' No or some other selection type exists, so do something else (optional) ...
End If

The first part of the If statement is usually required, but the "Else" part is optional. Whether it is omitted depends on the macro.

' Normal selection type is overly general (not recommended for text macros)
If Selection.Type = wdSelectionNormal Then
' A normal selection exists, so do something important ...
End If

See our brief introduction to conditional statements for more explanation.

Problem with a normal selection detection

The logic sounds good … but unfortunately, this obvious check for a normal selection is too ambiguous for many writing and editing macros, and the Microsoft documentation is terse on the topic.

What's the problem?

The above statements are not wrong, per se, but VBA is overly general with what it classifies as a normal selection. Both statements are probably too vague for editing macros used in a document containing anything other than text, and it's not a good practice to hope the user remembers the times when not to use a macro.

Since a normal selection isn't just a text selection, it can include shapes, tables, and even non-contiguous selections. Word can obviously define what normal means for selections however they want, but none of these selection variations seem to fit the intuitive meaning of "normal" in a word processing application.

In the above conditional statement, either case includes selection possibilities that could confuse or even mess up some editing macro steps. An exhaustive validation to exclude unwanted cases from an editing macro is messier than we need or want.

In essence, the conditional statement really doesn't tell us much in regards to making an informed decision in an editing macro. We know it isn't a block selection or just a shape or related to parts of a table but not much else.

What do we do then?

We flip the condition and check for no selection instead.

Condition for no selection (insertion point)

We'll use the opposite condition and check whether the document contains just an insertion point where no content is selected.

' Condition for an insertion point with nothing selected
Selection.Type = wdSelectionIP ' This condition works better ...

Why is this better?

While it is logically annoying, reversing the Selection condition works more consistently for our detection logic in editing macros because an insertion point is a more specific Selection Type than a normal one. More specifically for our purposes, an insertion point can't include shapes, table elements, frames, or non-contiguous selections.

No selection conditional statements

Flipping the conditional statement order, we instead check for not a selection as the main case.

' Better selection detection (but not a perfect solution)
If no selection exists (an insertion point) Then
' No selection exists, so do something important ...
Otherwise
' A selection exists, so do something else important (optional) ...
End the selection check

It's a little awkward until you get used to it, but it's reduces the number of gotchas that might circle back to bite us later. The revised check doesn't solve every issue because the Else part can still refer to other types of selections, but it takes us further down the path of creating well-behaved editing macros.

Translating this into VBA, it becomes:

' Check whether the selection is an insertion point
If Selection.Type = wdSelectionIP Then
' Document contains only an insertion point, so do something important ...
Else
' Some content is selected, so do something else important (optional) ...
End If

If we only need to check for no selection, we can omit the second part.

If Selection.Type = wdSelectionIP Then
' No starting selection, so do something important ...
End If

This simplified conditional statement would apply to circumstances where extra steps are required only if no content is selected.

Avoid the no selection type

If you scan through the Selection Type constants, you might notice a constant wdNoSelection—

What?

Why did he use wdSelectionIP? This dude’s a fraud!

Well, that may be up for debate, but for a typical selection-based macro decision, the wdNoSelection type does not work in the intuitive sense of its name. Rather, it refers to a selection that does not exist in the document but not in the intuitive sense of an insertion point with no content selected. Every document needs a Selection, so this constant refers to something more like an error state in a document where the Selection is missing for some reason. Thus, we will almost never use wdNoSelection unless we're checking for an unusual document error.

If you don’t believe the above claim, copy the macro below and do a few tests. It is difficult to create a situation in a typical working document that has the wdNoSelection type. Using wdSelectionIP as in the example above is a little awkward, but it works the way we expect when we want to check for no selection in a regular, everyday Word document.

What about text inside shapes and tables?

This is another place where the logic can become a tad tricky.

If the insertion point (with no text selected) is inside a shape or a table, the selection type will still be wdSelectionIP. This case is probably okay for many editing macros since the macro will often function as intended. Trouble is more likely to arise when the shape itself, or whole cells, columns, or rows of a table are selected; but those would not be categorized as an insertion point.

Special text selection types

We are focused on text-based selection types, but special selections may still work in some editing macros.

Non-contiguous selections

We can create non-contiguous selections using the Command key on Mac or Control on Windows and dragging across more text (keyboard selection works also) even if the text is not connected to the other selection(s). Non-contiguous selections are distinct from block selections even though they have qualitatively similar behaviors in a document.

Checking non-contiguous selections

Unfortunately, a non-contiguous selection is identified as a normal selection type in Word, so we can't distinguish between a single span or multiple discontinuous portions of text. For example, if we try to access the discontinuous selection’s text property, we'll get the text of the last addition.

Guarding against non-contiguous selections

Word VBA doesn’t give us much control over non-contiguous selections (as April 2025), but if we need to reduce such a selection without collapsing it entirely, the ShrinkDiscontinuousSelection method will simplify the selection.

Selection.ShrinkDiscontiguousSelection

This method shrinks the selection down to the most recent addition. It has no effect on an insertion point or only one selected span of text, so we could include the command without fear of ruining the starting selection in regular use cases.

Non-contiguous selections are a nice feature in Word, but I generally haven’t worried about guarding against them when creating my own writing macros. However, you might need to be more cautious in your own macros if you use non-contiguous selections often.

Block selections

The Selection type wdSelectionBlock corresponds to special block (or columnar) selections. They seem similar to non-contiguous selections in that multiple regions of text are selected, but block selections are vertically connected.

Creating block selections

We can create a block selection in Word by holding the Option key on a Mac (or Alt on Windows) and selecting text using the mouse. Alternatively, the shortcuts Command+Shift+F8 on a Mac or Control+Shift+F8 on Windows along with the arrow keys will also select a block of text. Either version creates a rectangular selection spanning multiple lines of text usually without including complete lines.

About block selections

Block selections are nice when you need them, but the use cases don’t pop up often for writers in my experience. They are not the same as non-contiguous selections in a macro, but they work similarly in practice in that Word will act on all pieces of the selected text depending on the command given.

Accessing the Selection's Text property in a macro when a block selection exists will cause the macro to act weirdly (the selection expands in a strange way to include all covered paragraphs in addition to the original block selection). Also, the Text property only contains the first partial line of the selection text, so it’s probably best to avoid manipulating block selections in macros.

Guarding against block selections

Word VBA doesn’t give us much control over block selections in macros (as of April 2025). We could avoid any issues with initial block selections by checking for it and just collapsing the selection if one is detected. Fortunately, we have a block selection type we can use.

If Selection.Type = wdSelectionBlock Then
' Collapse existing block selection to avoid any issues
Selection.Collapse
End If

The previous ShrinkDiscontiguousSelection method of the Selection does not work with block selections, so Word treats of them as different selection types despite the apparent similarities. In practice, this additional check would probably be included as a separate ElseIf part (see our brief introduction to conditional statements for more explanation) of the selection detection logic given above.

' Check whether the selection is an insertion point or a block selection
If Selection.Type = wdSelectionIP Then
' Document contains only an insertion point, so do something important ...
ElseIf Selection.Type = wdSelectionBlock Then
' Block selection detected, so probably collapse it ...
Else
' Some content is selected (other than a block selection), so do something
' else important (optional) ...
End If

This will ward off block selection issues at the cost of making the macro messier by handling yet another special case. I haven’t guarded my own macros against potential block selections, but you might have a special workflow where it could cause problems.

Validating Selection Types

The following is a simple, even if verbose, macro that pops up a little message informing the user of the current selection type in a document. It's not meant as a stand-alone editing macro, but it might save some time if you want to better understand the selection status in a document when creating a macro, particularly when working with some more unusual document selections.

Sub TestSelectionTypes()
' Test various selection types and notify the user which one applies

' Store the selection type as text to include in a message below
Dim sType As String
sType = "a problem" ' Default message indicates a problem
If Selection.Type = wdSelectionIP Then
sType = "an inline paragraph (intuitively no selection)"
End If
If Selection.Type = wdNoSelection Then
sType = "a non-selection (most likely a document error)"
End If
If Selection.Type = wdSelectionNormal Then sType = "a normal"
If Selection.Type = wdSelectionBlock Then sType = "a block"
If Selection.Type = wdSelectionRow Then sType = "a table row"
If Selection.Type = wdSelectionColumn Then sType = "a table column"
If Selection.Type = wdSelectionShape Then sType = "a shape"
If Selection.Type = wdSelectionInlineShape Then sType = "an inline shape"
If Selection.Type = wdSelectionFrame Then sType = "a frame"

' Let the user know the detected selection type (only one is possible)
MsgBox "This is " + sType + " selection"
End Sub

MsgBox is a standard Word function to pop up a basic information dialog box. While it has several parameters, it only requires some text to include in the dialog. We concatenated several strings together for the message including the identified text selection type.

A selection can only have one type even if the cases might overlap some in practice. If this were for a practical editing macro, we would use a Select Case statement instead of a stack of disconnected If statements, but I did not want to introduce a new command just for a quick and dirty testing macro.

Affiliate Links

If you're interested in using Word or another tool related to the article, check out these affiliate links. I may make a small commission if you purchase when using them, but there is no increase in cost for you, and it helps to support this site and associated content.

I've been using Microsoft for Business for commercial use (that's us writers) on one of the lower pricing tiers for years. I get to use my macros, have online storage, and don't have to worry about software updates.