TypeText method inserts text into a Word document : Word Text « Word « VBA / Excel / Access / Word






TypeText method inserts text into a Word document

 
Sub InsertText()
    Dim wdApp As Word.Application
    Dim wdDoc As Document
    Dim wdSln As Selection
    
    Set wdApp = GetObject(, "Word.Application")
    Set wdDoc = wdApp.ActiveDocument
    Set wdSln = wdApp.Selection
    
    wdDoc.Application.Options.Overtype = False
    With wdSln
        If .Type = wdSelectionIP Then
            .TypeText ("Inserting at insertion point. ")
        ElseIf .Type = wdSelectionNormal Then
                If wdApp.Options.ReplaceSelection Then
                    .Collapse Direction:=wdCollapseStart
                End If
               .TypeText ("Inserting before a text block. ")
        End If
    End With
    Set wdApp = Nothing
    Set wdDoc = Nothing
End Sub

 








Related examples in the same category

1.Define a Range
2.The Range object selects paragraphs.