InsertBefore Method

Applies To

Range object, Selection object.

Description

Inserts the specified text before the specified selection or range. After the text is inserted, the selection or range is expanded to include the new text.

Note You can insert characters such as quotation marks, tab characters, and nonbreaking hyphens by using the Chr function with the InsertBefore method. You can also use the following Visual Basic constants: vbCr, vbLf, vbCrLf and vbTab.

Syntax

expression.InsertBefore(Text)

expression Required. An expression that returns a Range or Selection object.

Text Required String. The text to be inserted.

See Also

InsertAfter method, InsertParagraph method, InsertParagraphBefore method, InsertSymbol method, Text property, TypeText method.

Example

This example inserts the text "Hamlet" (enclosed in quotation marks) before the selection and then collapses the selection.

With Selection
    .InsertBefore Chr(34) & "Hamlet" & Chr(34) & Chr(32)
    .Collapse Direction:=wdCollapseEnd
End With
This example inserts the text "Introduction" as a separate paragraph at the beginning of the active document.

With ActiveDocument.Content
    .InsertParagraphBefore
    .InsertBefore "Introduction"
End With
This example inserts all the font names in the FontNames collection into a new document.

Documents.Add
For Each aFont In FontNames
    With Selection
        .InsertBefore aFont
        .Collapse Direction:=wdCollapseEnd
        .TypeParagraph
    End With
Next aFont