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

Introduction to the Selection

Word • Macros • Basics
Peter Ronhovde
30
min read

The Selection in Word VBA represents what we see and manipulate on the screen in real time. We cover the basics of using it in writing and editing macros by introducing movement methods, selection types, collection properties, and other features. We also compare and contrast it with a similar Range object.

Thanks for your interest

This content is part of a paid plan.

Introduction to the Word VBA Selection

We’ve used the Selection in various beginner macros. It’s mostly intuitive, as is VBA in general, but what is it? This article digs a bit deeper, so we can write more informed writing and editing macros in Word.

Document selections

A selection (with a lowercase s) is what we see in the document as we type and edit. It may span text or other document content, or it might just be an insertion point (i.e., the blinking I-bar waiting for you to type some new text).

Example user selection
Example text selection

What is the Selection?

The Selection (with a capital S) is VBA’s internal representation of the visible selection we see in a document. It consists of various commands (called “methods”) which perform actions like moving or extending the Selection, deleting document content, etc. It also includes various properties which store data about it such as its Start and End positions. Given what it represents, only one Selection exists per document, and any changes made to it are (usually) immediately visible on the screen.

Using the Selection

In VBA, we access the Selection using the obvious keyword Selection:

Selection ' Not done ...

Often, we indent the command as shown, but that’s only for us humans as we organize our macro steps. The VBA editor doesn’t care. Another article provides a quick introduction to creating an empty macro.

Selection is visible on screen

Any manipulation of the Selection is immediately visible on the screen while the macro runs (unless screen updates have been turned off). For short macros, this works well. For longer macros, it can cause the screen to jitter or flicker which is unsightly.

Using properties or methods

We access methods or properties of the Selection (or any other VBA object) simply by using a dot . after the name. Then we type the name of the property or method we want to use. For example, this statement represents the Start position of the Selection in the document.

Selection.Start

Document positions are counted as characters from the beginning of the document.

Including command options

Most commands have obvious actions based on their name, and the options have relatively obvious effects on what happens. For example, this command moves the insertion point down by one line in the document.

Selection.MoveDown ' Valid but not done ...

Most methods allow options (called arguments when we provide them to the command) to allow more control over what happens. We can specify options on many commands like:

Selection.MoveDown Count:=3

The above command moves the insertion point down by three lines (see more on the movement methods below).

Comparison to a Range variable

The Selection and a Range are similar objects in VBA with many shared features. Many of the properties and methods are similar enough that we can consider a Range variable much like an invisible Selection in the document.

Similarity to a Range

The Selection is essentially a special but also unique document Range. Important similarities between the Selection and Ranges are:

  • Ranges share many of the same move methods with the Selection such as moving it around the document, copying, pasting, deleting, inserting text, etc.
  • Ranges have Start and End positions which act almost exactly like the same properties of the Selection.
  • Ranges and the Selection can both access collections of contained document elements like sentences, characters, paragraphs, hyperlinks, etc.

A few more exist, but these are the common ones.

Differences with a Range

A few differences exist between a Range and the Selection object.

  • Only one Selection exists per document, but we can define as many Range variables as needed for a macro.
  • The Selection has an “active” side, either its start or end, but Ranges do not.
  • Some Selection methods are not available to Ranges. The reverse is also true for Ranges but to a lesser extent.
    • Range commands that move between lines in a document are clunkier than for the Selection.
    • The Selection has some specialized move commands such as MoveUp or MoveDown which are convenient at times.
    • Ranges can access the case of words, compute statistics, access spelling and grammar errors, etc.
    • The Selection can manipulate some character formatting methods that are not directly accessible with ranges.
  • Range variables evaporate into the computer world when a macro finishes leaving only the changes made to the document, but the final state of the Selection at the end of the macro is represented in the document.
  • Selection updates are immediately seen in the document unless screen updates are turned off.
  • Ranges are invisible to the writer unless the macro includes steps that specifically change the document.

More differences exist of varying importance. We elaborate on some of the more common distinctions a little more below. We can always access the Range of the Selection anyhow if we need to access any Range specific properties or methods, or we could select the Range variable and make it the Selection, if needed.

Use the Selection or a Range variable?

Using the Selection in a macro is convenient, but using a Range variable is generally preferable.

Issues using the Selection

Why might we avoid using the Selection in a particular macro?

  • Changing the Selection immediately and visibly updates the screen as the macro runs.
    • For longer macros the screen updates may make the macro run much more slowly as Word attempts to update the screen for every tiny change.
    • Real time changes to the Selection may be unsightly and distracting when the screen flickers as the macro updates the document.
  • If a macro using the Selection encounters a problem, any changes up to that point have already been made in the document, so the user sees an intermediate and probably unintended result.

When to use the Selection?

Why might we choose or be forced to use the Selection in a macro?

  • When the macro is simple, probably containing only a few steps, it’s more convenient to use the Selection. The changes are essentially immediate from the user’s perspective anyhow, so no significant downside exists.
  • Some internal document bookmarks are not available to a Range variable, so the Selection may be required.
  • The Selection can easily move by lines as seen on the screen, but the same moves are clumsy when using a Range variable (must use a GoTo method).

Some nice macros using the Selection can even be accomplished in a single-line command. See for example, a macro to delete the current paragraph or select the current sentence.

When in doubt, it's probably better to use a Range variable to carry out the macro task. See our introduction to Word VBA Ranges for information about using Range variables in editing macros.

Common Selection features

Many of the useful properties and methods of the Selection are similar to those of a Range variable, and we tend to use them similarly in writing and editing macros. This article is not an exhaustive commentary on any specific properties or methods, but most individual articles carefully explain them when they are used.

Summary of useful Selection properties

In the context of editing macros, more commonly used properties related to the Selection include:

  • Text
    • Text (plain text)
    • FormattedText (formatted text as seen on screen)
    • Font and Style (character or paragraph)
  • Collections of document content partially or fully spanned
    • Characters, Words, and Sentences
    • Paragraphs and Bookmarks
  • Find (access all Find search features)

Other properties exist, but the above will carry us most of the way in our editing macros journey.

Summary of useful Selection methods

Some often-used methods include:

  • Delete (without using the clipboard)
  • Copy, Cut, and Paste (standard clipboard actions)
  • BoldRun and ItalicRun (typical text formatting)
  • Insert content
    • InsertBefore and InsertAfter (plain text)
    • InsertParagraph, InsertParagraphBefore, and InsertParagraphAfter (paragraph breaks)
    • InsertBreak (any content break)
  • Movement methods
    • Move, MoveLeft, MoveRight, MoveUp, and MoveDown (typical unit-based)
    • GoTo, GoToNext, and GoToPrevious (move to specific content types)
    • StartOf and EndOf (constrained unit-based)
    • MoveWhile and MoveUntil (character-based)
  • Extension (or contraction) methods
    • Collapse
    • Expand (constrained unit-based in both directions)
    • StartOf and EndOf (constrained unit-based extension in one direction)
    • MoveStart and MoveEnd (unit-based)
    • MoveStartWhile and MoveEndWhile (character-based)
    • MoveStartUntil and MoveEndUntil (character-based)
  • Next and Previous (access neighboring content)

It's a long list, but the various methods are in logical groups, and all of them are useful in different editing contexts.

What was left out?

The Selection includes many more properties and methods, but many of the others apply to specialized tasks or don't contribute often to typical novel editing. For now, we omit anything related to tables, lists, or shapes; but they could apply to non-fiction documents.

Extent of the Selection in the document

The Selection has Start and End position properties which indicate the beginning and ending of the selected document content on screen. The Start position is obviously on the left side toward the beginning of the document and End is on the right side.

  • If the Start position is less than the End, then any content in between the two positions is in the document selection.
  • If the Start and End positions are the same, the Selection is an insertion point in the document (i.e., the blinking I-bar waiting for new text).

One side is considered “active,” but the distinction usually doesn't matter in practice. A Range variable also shares Start and End properties except a Range doesn’t have an active side.

VBA cannot manipulate non-contiguous selections

While a writer can create and use block or non-contiguous selections in Word during real-time use, a macro has no way to create or control them (as of April 2025).

Collapsing the Selection

A common task in a macro is to remove any selection (lowercase s) around document content using the Collapse method.

Selection.Collapse

As the name implies, this command collapses the document selection to an insertion point specifically toward its beginning. It has no effect on an insertion point, so after using it, we can be confident we are working with an insertion point in the document. This helps us guard against ambiguous or perhaps unforeseen conditions when creating a macro.

We can instead collapse toward the end of the Selection using the Direction option.

Selection.Collapse Direction:=wdCollapseEnd

This variation comes in handy sometimes. wdCollapseEnd is one of the two direction constants. The default option is wdCollapseStart which is why we didn’t need to specify it in the first Collapse command.

Selection move methods

One of the more important tasks when using the Selection in a macro is controlling its location in the document. We summarize the categories of available movement methods with a some quick examples.

Unit-based movement

Convenient features of the Selection include the specialized move methods MoveRight, MoveLeft, MoveUp, MoveDown which do exactly what the names imply. For example, the MoveUp method literally moves the Selection up one line in the document much like tapping the Up arrow key.

Selection.MoveUp ' Move Selection up one line

Several other methods allow us to manipulate the position of the Selection in a similar manner.

  • The Move method is basically a general purpose move command.
  • StartOf and EndOf also move by a unit but constrain the move within the current unit.
Movement units

The available movement Units are mostly intuitive and correspond to common movement cases.

  • Up and down movement: wdLine, wdParagraph, wdScreen (works something like PageUp or PageDown on your keyboard), or wdWindow (top or bottom of the active window).
  • Left and right movement: wdCharacter, wdWord, and wdSentence

A table of standard Word move units mimic how a user would normally move around in a document using the keyboard. The default unit varies by the move method. The wdLine unit is the default with MoveUp or MoveDown, so we normally omit it, but we could use a paragraph unit, for example.

Selection.MoveUp Unit:=wdParagraph

This command moves to the beginning of the current paragraph or to the previous paragraph if already positioned at the beginning. All command option assignments use a colon equals := symbol for the assignment.

Character-based movement

When working in a document, we may need to jump to a comma or some other character, so another category of movement navigates by specific characters.

Move to specific characters

If we need to move the Selection over to a specific character (or any of a set of characters), we use the MoveUntil method.

Selection.MoveUntil ' Not done ...

These methods cannot be used without at least one argument because we must specify a character set to use for the movement. Assign a plain text string, usually in double quotes like "xyz", to a character set option named Cset.

Selection.MoveUntil Cset:="xyz" ' Default move is forward

This command collapses the Selection and moves it forward in the document (by default) to the next x, y, or z character it encounters. Specific articles cover how to include special characters such as paragraph marks or tabs when they are needed.

Moving over specific characters

When we need to skip all occurrences of a certain character (or any of a set of characters), use the MoveWhile method.

Selection.MoveWhile Cset:="xyz"

This command instead moves the Selection forward while it finds an x, y, or z at the Selection position. Meaning, it stops as soon as it finds a character that is not one of those given in the Cset option.

Specify backward direction

If we instead need to move backward in the document, include the Count option.

Selection.MoveUntil Cset:="xyz", Count:=wdBackward ' Force backward move

The wdBackward constant tells the command to keep moving past any number of matched characters. The two options must be separated by a comma.

Not a Find search

These two methods are not used like the Find property which allows us to perform regular Word searches in VBA. Find searches for a specific sequence of text. For example, a search with Find for "xyz" literally looks for an "x", followed by a "y", followed by a "z"; but the above commands look for any of the characters in the set individually in any order.

GoTo document elements

The GoTo method is a general movement method that jumps the Selection to one of several document elements.

Selection.GoTo ' Not done ...

GoTo can move through the document by lines or pages, but it gives us the ability to jump to other document elements that the above move commands cannot target directly. Too many variations exist to be complete, so we'll look at three quick examples that might be useful in a writing an editing macro.

Jump to a specific page

GoTo has more options than most other move commands. We begin with a What option from a GoTo item constants table to specify an element category.

Selection.GoTo What:=wdGoToPage ' Still not done ...

Another constants table indicates a direction, but it includes more possibilities than just forward or backward. We can indicate an absolute item count in the overall document, a count relative to the current position, or the first or last occurrence. We assign the direction constant wdGoToAbsolute in this example to the Which option.

Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute ' Almost there ...

We need include the Count option to indicate the specific page. The following command jumps to the second page in the document regardless of our initial location.

Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=2

See how long the command is? It's almost unwieldy but relatively straight forward.

Jump to a relative page

If we want to jump to a page above or below the current one, change the direction constant to wdGoToRelative.

Selection.GoTo What:=wdGoToPage, Which:=wdGoToRelative, Count:=3

This command jumps forward in the document by three pages.

If we know we specifically want the next page (or whatever element), the GoToNext method is easier.

Selection.GoToNext What:=wdGoToPage ' Easier to use
Jump to a Bookmark

Another common use case for editing macros would be jumping to a specific bookmark. The initial command is similar to above except we specify the What item as wdGoToBookmark.

Selection.GoTo What:=wdGoToBookmark ' Not done ...

We need to specify the bookmark name. Several previous editing macros implement faster bookmarks. A typical editing bookmark was named PrimaryEdit, so we assign as it as a "plain text string" in double quotes to the Name option.

Selection.GoTo What:=wdGoToBookmark, Name:="PrimaryEdit"

If the bookmark spans document content, it will be selected. While the command is a tad long, it's intuitive. If you prefer a different approach, we could alternatively select a bookmark using the Bookmarks collection.

See the separate Quick Bookmarks article about validating whether the bookmark exists before attempting to jump to it, or the macro will crash.

GoTo comments and caveats

GoToNext and GoToPrevious are just more convenient special case methods that force relative movement specifically to the next or previous document element.

The GoTo method and its siblings work a little differently with Range variables, so review the methods in the introduction to Ranges article before using any of them with a Range.

Picking the correct method

Several movement methods exist, so pick the best approach for the task at hand depending on the needs of the macro. For example, the MoveLeft method has some caveats about how it works depending on whether it starts at the beginning of a document element. We'll move left by one sentence as a specific example.

Selection.MoveLeft Unit:=wdSentence ' May jump to previous sentence

If the Selection is anywhere inside the sentence, it will move to the beginning of the current sentence.

Okay, no problem so far …

However, if the Selection is already positioned at the beginning of a sentence, the MoveLeft method will move the insertion point to the previous sentence in the document.

A human handles ambiguities like this with barely an extra thought, but they are annoying when creating a macro that needs to do something specific regardless of the initial position. We could be more specific and avoid the movement ambiguity by using the StartOf method instead.

Selection.StartOf Unit:=wdSentence ' Moves no further than current sentence

StartOf still moves to the beginning of the current sentence, but it will not move past the beginning of the current sentence. We don't need to worry about the two different cases, so StartOf makes the macro easier to create.

Various articles explain the move commands in more detail as they are applied to specific macro tasks.

Extending or contracting the Selection

Multiple methods allow us to control the extent of the Selection. They follow a similar pattern to the move methods above, but they work specifically with the Start or End positions of the Selection.

Document unit-based extension or contraction

The methods MoveStart and MoveEnd work like the move commands above except they only move the named side of the Selection. For example, this command extends the End position (right side) of the Selection to the end of the current paragraph (or the next one if its already there).

' Extend the Selection forward in the document (default)
Selection.MoveEnd Unit:=wdParagraph

The default move unit is by a character, so we usually need to specify a unit.

We could also contract the Selection using a negative value with the Count option:

' Contract the Selection by moving End backward in the document
Selection.MoveEnd Unit:=wdParagraph, Count:=-1

Negative Count values move backward in the document. Whether this extends or contracts the Selection depends on the respective side of the Selection.

Constrained unit-based extension or contraction

We can extend the Selection both directions using the Expand method.

Selection.Expand Unit:=wdParagraph

This command extends the Selection both directions to encompass the entirety of the current paragraph. The default unit is a word from a standard units constants table, but we usually want something else.

Expand is nice in the sense that it will not grow the selection beyond the given unit if it already spans that unit of content. Moreover, it works separately on each side, so it will actually expand to include two partially selected paragraphs.

This method will not contract the Selection even if we change the unit to a smaller sized element. We would need to first collapse the select and then re-expand it around the smaller unit.

Watch out for Shrink

Despite the seemingly converse actions by method names, Expand and Shrink do not reverse each other in terms of behavior. The Shrink method works only in specific unit step sizes.

' Shrink works with specific document element units steps which
' we cannot change
Selection.Shrink ' Not as useful as Expand ...

The action asymmetry is unfortunate, but if we needed to step down to a smaller unit size, we could just collapse the Selection first.

' Manual contraction of the Selection to the current word
Selection.Collapse
Selection.Expand Unit:=wdWord

The catch is the Expansion will act at the collapsed position meaning at the beginning of the larger unit. This is what we would expect with a "shrink" method that acts like the opposite of Expand.

Character-based extension or contraction

We can perform character-based Selection extensions (or contractions) using MoveStartUntil, MoveEndUntil, MoveStartWhile, or MoveEndWhile as needed. For example, this command extends the Start position of the Selection backward in the document until it finds a space " " character.

' Move the Selection backward to the nearest space
Selection.MoveStartUntil Cset:=" ", Count:=wdBackward

The Start or End positions can move either direction in the document, so we can extend or contract the Selection as needed. The respective commands otherwise act like the above MoveUntil and MoveWhile methods, but we need four of them to accomplish the various extension or contraction tasks.

Movement extension option

Most move commands automatically collapse the Selection to an insertion point on the move, but several include an Extend option which allows them to change the Selection but still take advantage of the benefits of the command.

For example, the EndOf method conveniently constrains any movement to the current document unit specified. We can include the Extend option to leverage this aspect of the method for selections also.

Selection.EndOf Unit:=wdSentence, Extend:=wdExtend

We assign the wdExtend constant to the Extend option. Of course, the default is wdMove which just moves the Selection. This particular command extends the End position of the Selection forward in the document to the end of the current sentence but no farther even if the Selection is already positioned at the end of the sentence.

Technically, MoveRight, MoveLeft, MoveUp, and MoveDown also have an Extend option; but in practice, they do not feel nearly as useful as StartOf and EndOf with the Extend option.

Did it go too far?

A contracted selection might finish the macro as an insertion point. Most of the above commands can extend or contract the Selection, but if the Start position ever exceeds the End position, the Selection is effectively collapsed; and the End position is set equal to Start. The reverse occurs if the End position ever moves before Start.

Selection Types

For many macros, we may want to take different actions depending on whether an initial selection exists in the document or not when the macro is run. Sometimes we take an extra step (such as selecting the whole starting paragraph if no user selection exists), or we might just do different steps in either case.

Conceptual Selection Type check

A quick and dirty example test might look something like:

' Check if no selection exists in the document
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

What we do in either case depends on the macro.

General (kind of) Selection Type check

Without much explanation, we translate this conceptual decision logic into VBA.

' 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) ...
' Selection could contain non-text elements
End If

Most of our articles focus on selections that involve text in one way or another, but the Else case could include non-text elements if no other checks are made. Being more specific is messier, so including any additional checks is a preference and a risk versus reward evaluation.

For more details on the reasoning behind this conditional statement—such as why it checks for no initial selection as opposed to a normal selection—a previous article covers an introduction to Selection types in VBA, and another article introduces conditional statements in VBA.

Only no selected content check

The Else part is optional, so the entire part could be omitted if it is not needed, leaving us with the first case of the If statement.

' Check whether the selection is an insertion point
If Selection.Type = wdSelectionIP Then
' Document contains only an insertion point, so do something important ...
End If

The extra steps are run only if no selection exists in the document in the intuitive sense.

Only selected content check

If we only need to do something different if a valid selection exists, one approach is to check for a "normal" selection type.

' Check whether a typical document selection exists (not fool proof)
If Selection.Type = wdSelectionNormal Then
' Some content is selected, so do something important ...
' Specific type of selected content could vary
End If

For most practical purposes, this conditional statement only excludes an insertion point. The problem is a normal selection is a vague term in Word since many content selections will be identified as such. See the introduction to Selection types article for more explanation.

Storing the current Selection as a Range

Often, we want to manipulate something at or near to the user’s current position in a document. Using a Range allows us to work invisibly until we're ready to reveal or make any changes, so storing the initial Selection in a Range variable is a frequent early step in a macro.

Since a Range isn’t quite the same thing as a Selection, we must refer to its Range property.

' Document range of the current Selection (does not do anything by itself)
Selection.Range ' Not done ...

We could take various actions with the Range, but in this case, we just want to store the same document range in a separate and independent Range variable.

Set MyRange = Selection.Range

Since a Range contains more information than just a value like a number or plain text, we need to use “Set” when assigning it to a Range variable. See our brief introduction to Ranges for more explanation.

Our Range variable MyRange now spans the same document content (which could be empty) as the Selection at this moment in the macro. If it spans any document content, its Start position is less than the End position. If the initial Selection was an insertion point, its Start and End positions are the same.

Using Selection collections

Another common task is to access and modify parts of the document in or near the Selection. Many times we'll refer to the various collections of spanned content which include the document elements partially or fully spanned by the Selection.

For example, if we want to modify a specific paragraph contained in the Selection, we often start by accessing the Paragraphs collection.

Selection.Paragraphs ' Not done ...

The Paragraphs property contains a collection of all paragraphs in the Selection. Occasionally, we'll use this collection as part of a loop over all paragraphs in the Selection, but more often we'll refer to a specific paragraph.

First or Last Paragraph

Conveniently, we can access the first Paragraph by referring to its First property.

Selection.Paragraphs.First ' Still not done ...

This is the most common paragraph to use. Even if there is only an insertion point in the document, the current paragraph is still the “first” paragraph.

Similarly, we can access the last paragraph with its Last property.

Selection.Paragraphs.Last ' Still not done ...

Often, these are the only paragraphs we'll need. If the Selection is inside one paragraph, the first and last paragraphs are the same.

Example changing the current paragraph style

We almost always follow up with an action using one or more of the various Paragraph methods or properties. For example, we could modify the paragraph style using the Style property.

Selection.Paragraphs.First.Style = "Normal"

The current paragraph would be changed to have a Normal style. Some significant gotchas exist when working with styles, so see a previous article where we discuss style toggles for more information.

Accessing other paragraphs

If we need a paragraph somewhere in the middle of the Selection, we again refer to the Paragraphs collection, but we include the paragraph number (counted from the first one in the Selection) inside parentheses.

Selection.Paragraphs(4) ' Not done ...

This command refers to the fourth paragraph in the Selection assuming it exists. If not, it causes an error in the macro execution, so we would probably need some extra steps around it for validation.

In writing and editing macros, we usually don't need to directly access individual paragraphs somewhere in the middle of the Selection. If it spans multiple paragraphs, we will more likely to do the same thing to all paragraphs in the Selection. See looping over collection items below.

Collection item types

Is the collection item a Range or some other object? We need to be aware of what the different collection references give us, so we use them properly. If not, VBA will complain and often crash the macro if a method or property doesn't exist for that data type.

Collections of object types

Some collections spanned by the Selection like Paragraphs, Hyperlinks, Shapes, and a few others contain object data types as VBA represents them internally. As such, they have their own methods and properties which we can use as needed.

Selection.Paragraphs.First.Indent ' Indent the first paragraph

This is a valid command because First refers to the first Paragraph in the Selection, and a Paragraph object has an Indent method. Occasionally, this gets in the way of what we want to do with the content (see example below).

Collections of document ranges

Other collections like Sentences, Words, or Characters instead store the respective ranges spanned by the document content. If we need to do something, we need to refer to the available Range methods or properties. For example, this command would be invalid:

' Invalid because the first paragraph Range does not have an Indent method
Selection.Sentence.First.Indent

This fails because a Range does not have an Indent method like a Paragraph object does above.

Since the first sentence in the Sentences collection is just a Range, we could instead get the text using the Text property.

' Valid because the Range (of the first sentence) has a Text property
Selection.Sentences.First.Text

This command works because all Range variables have a Text property.

Some methods or properties may be the same for different objects. This is often allowed as a convenience, but how it works may vary some depending on the data type.

Selection.Paragraphs.First.Style = "Normal" ' Valid style assignment
Selection.Sentences.First.Style = "Normal" ' Also valid

For the Paragraph version, the style will only apply to the first paragraph. The sentence version will also apply the paragraph style to the full paragraph even though a sentence is only part of a general paragraph. For other general Range variables, the corresponding command would apply the style to every paragraph contained in the range. See our style toggles article which discusses issues with using styles in macros.

Examples deleting the current sentence or paragraph

What if we want to delete the current sentence?

A sentence in the Sentences collection is already a Range, so we can just delete it directly using its Delete method.

' A sentence is already a Range, so just delete it
Selection.Sentences.First.Delete

However, a Paragraph is its own data type in Word VBA which doesn't have a Delete method, so we need to first refer to the Range of the Paragraph.

Selection.Paragraphs.First.Range ' Not done ...

Then we can delete it using the Delete method of its Range.

' Must refer to the Range of a Paragraph to delete it
Selection.Paragraphs.First.Range.Delete

Using these collections of spanned content, we can accomplish some very useful tasks with limited effort.

Looping over collections

Another common task would be to do something to all paragraphs (or whatever collection) in the Selection. The specifics of this generic task requires loops, of which several types exist. It's a big enough topic to leave the details to another article, but this quick and dirty example loops over all paragraphs in the Selection.

For Each CurrentParagraph In Selection.Paragraphs
' Do something to the current paragraph ...
Next CurrentParagraph

This is called a "For Each" loop … because of the first two words of the command. It is a convenient command to do something to every paragraph in the collection without having to know how many paragraphs exist. It even works with only one paragraph.

The CurrentParagraph will change as Word iterates through each successive Paragraph in the Paragraphs collection. We can place whichever commands we need inside the loop, but they should logically refer to the current paragraph or at least have something to do with the loop. Place any other commands outside the loop.

Do not always need a loop

VBA will automatically apply some actions to all paragraphs in the Selection. For example, we could just apply a style to the Paragraphs collection directly.

' Valid because the Paragraphs collection has a Style property for all of them
Selection.Paragraphs.Style = "Normal"

But a collection will not have every desired method or property, so we'll need loops for some actions.

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.