Class TextRange (PowerPoint VBA)

Contains the text that's attached to a shape, and properties and methods for manipulating the text.

The main procedures of class TextRange are Copy, Delete and Select

Set

To use a TextRange class variable it first needs to be instantiated, for example

Dim tre as TextRange
Set tre = ActiveWindow.Selection.TextRange

The following procedures can be used to set variables of type TextRange: Selection.TextRange, TextFrame.TextRange, Characters, Paste, Replace, PasteSpecial, Find, InsertAfter, InsertBefore, InsertDateTime, InsertSlideNumber, InsertSymbol, Lines, Paragraphs, Runs, Sentences, TrimText and Words

Themes

The following procedures in this class have been grouped together and are described on a separate theme page

Format with its procedures BoundHeight, BoundWidth, Font and ParagraphFormat

Methods

These are the main methods of the TextRange class

Copy - Copies the specified object to the Clipboard.

ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Copy

Delete - Deletes the specified TextRange object.

ActiveWindow.Selection.TextRange.Delete

Select - Selects the specified object.

ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Select

Other Methods

Characters - Returns a TextRange object that represents the specified subset of text characters. For information about counting or looping through the characters in a text range, see the TextRange object.

Dim treCharacters As TextRange
Set treCharacters = ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Characters()

Find - Finds the specified text in a text range, and returns a TextRange object that represents the first text range where the text is found. Returns Nothing if no match is found.

Dim strFindWhat As String: strFindWhat = 
Dim treFind As TextRange
Set treFind = ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Find(FindWhat:=strFindWhat)

InsertDateTime - Inserts the date and time in the specified text range. Returns a TextRange object that represents the inserted text.

Dim treInsertDateTime As TextRange
Set treInsertDateTime = ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.InsertDateTime(DateTimeFormat:=ppDateTimeddddMMMMddyyyy)

InsertSymbol - Returns a TextRange object that represents a symbol inserted into the specified text range.

Dim strFontName As String: strFontName = 
Dim lngCharNumber As Long: lngCharNumber = 
Dim treInsertSymbol As TextRange
Set treInsertSymbol = ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.InsertSymbol(FontName:=strFontName, CharNumber:=lngCharNumber)

Lines - Returns a TextRange object that represents the specified subset of text lines. For information about counting or looping through the lines in a text range, see the TextRange object.

Dim treLines As TextRange
Set treLines = ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Lines()

Paragraphs - Returns a TextRange object that represents the specified subset of text paragraphs.

Dim treParagraphs As TextRange
Set treParagraphs = ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Paragraphs()

PasteSpecial - Replaces the text range with the contents of the Clipboard in the format specified.

Dim trePasteSpecial As TextRange
Set trePasteSpecial = ActiveWindow.Selection.TextRange.PasteSpecial()

Replace - Finds specific text in a text range, replaces the found text with a specified string, and returns a TextRange object that represents the first occurrence of the found text. Returns Nothing if no match is found.

Dim strFindWhat As String: strFindWhat = 
Dim strReplaceWhat As String: strReplaceWhat = 
Dim treReplaced As TextRange
Set treReplaced = ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Replace(FindWhat:=strFindWhat, ReplaceWhat:=strReplaceWhat)

RotatedBounds - Returns the coordinates of the vertices of the text bounding box for the specified text range.

ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.RotatedBounds X1:=, Y1:=, X2:=, Y2:=, X3:=, Y3:=, x4:=, y4:=

Runs - Returns a TextRange object that represents the specified subset of text runs. A text run consists of a range of characters that share the same font attributes.

Dim treRuns As TextRange
Set treRuns = ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Runs()

Sentences - Returns a TextRange object that represents the specified subset of text sentences.

Dim treSentences As TextRange
Set treSentences = ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Sentences()

Words - Returns a TextRange object that represents the specified subset of text words.

Dim treWords As TextRange
Set treWords = ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Words()

Properties

ActionSettings returns an ActionSettings object that contains information about what action occurs when the user clicks or moves the mouse over the specified shape or text range during a slide show.

Dim assActionSettings As ActionSettings
Set assActionSettings = ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.ActionSettings

BoundLeft returns the distance (in points) from the left edge of the text bounding box for the specified text frame to the left edge of the slide.

Dim sngBoundLeft As Single
sngBoundLeft = ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.BoundLeft

BoundTop returns the distance (in points) from the top of the of the text bounding box for the specified text frame to the top of the slide.

Dim sngBoundTop As Single
sngBoundTop = ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.BoundTop

Count returns the number of objects in the specified collection.

Dim lngCount As Long
lngCount = ActiveWindow.Selection.TextRange.Count

IndentLevel returns or sets the indent level for the specified text as an integer from 1 to 5, where 1 indicates a first-level paragraph with no indentation.

ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.IndentLevel = 2

LanguageID returns or sets the language for the specified text range.

ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.LanguageID = msoLanguageIDMixed

Length returns the length of the specified text range, in characters.

Dim lngLength As Long
lngLength = ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Length

Parent returns the parent object for the specified object.

Dim objParent As Object
Set objParent = ActiveWindow.Selection.TextRange.Parent

Start returns the position of the first character in the specified text range relative to the first character in the shape that contains the text.

Dim lngStart As Long
lngStart = ActiveWindow.Selection.TextRange.Start

Text returns or sets a String that represents the text contained in the specified object.

ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Text =