Mega Code Archive

 
Categories / VisualBasic Script / 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