Article ID: 160295
Article Last Modified on 1/19/2007
154568 ACC: How to Use Automation to Find a Location in a Word Document
Function FindBMark()
Dim WordObj As Word.Application
Dim WordDoc As Word.Document
Dim WordRange As Word.Range
Set WordObj = CreateObject("Word.Application")
Set WordDoc = WordObj.Documents.Open _
("C:\My Documents\Wordtest.doc")
WordObj.Visible = True
' Go to the bookmark named "City."
Set WordRange = WordDoc.Goto(What:=wdGoToBookmark, Name:="City")
WordRange.InsertAfter "Los Angeles"
' Uncomment the next line of code to print the document.
' WordDoc.PrintOut Background:=False
' Uncomment the next line of code to save the modified document.
' WordDoc.Save
' Uncomment the line of code to quit Microsoft Word without
' saving changes to the document.
' WordObj.Quit SaveChanges:=wdDoNotSaveChanges
Set WordObj = Nothing
End Function
?FindBMark()
Unbound Object Frame:
Name: UnboundObj
Locked: No
Private Sub EditWordDoc_Click()
Dim WordObj As Word.Application
Dim WordDoc As Word.Document
Dim WordRange As Word.Range
' Open Microsoft Word 97 in place and activate it.
Me![UnboundObj].Verb = -4
Me![UnboundObj].Action = 7
Set WordObj = Me![UnboundObj].Object.Application
Set WordDoc = WordObj.ActiveDocument
Set WordRange = WordDoc.Goto(What:=wdGoToBookmark, Name:="City")
WordRange.InsertAfter "Los Angeles"
Set WordObj = Nothing
End Sub
Additional query words: OLE find search
Keywords: kbhowto kbprogramming kbusage KB160295