Info

After you've set up bookmarks in a document, you can use the bookmarks to quickly move to a range. The following code automatically inserts text after four bookmarks that were previously set up in the document. The results are shown in Figure 16.10.

Sub UseBookmarks()

Dim myArray()

Dim wdBkmk As String

Dim wdApp As Word.Application Dim wdRng As Word.Range myArray = Array("To", "CC", "From", "Subject") Set wdApp = GetObject(, "Word.Application")

Set wdRng = wdApp,ActiveDocument,Bookmarks(myArray(0)).Range wdRng.InsertBefore ("Bill Jelen")

Set wdRng = wdApp.ActiveDocument.Bookmarks(myArray(1)).Range wdRng.InsertBefore ("Tracy Syrstad")

Set wdRng = wdApp.ActiveDocument.Bookmarks(myArray(2)).Range wdRng.InsertBefore ("MrExcel")

Set wdRng = wdApp.ActiveDocument.Bookmarks(myArray(3)).Range wdRng.InsertBefore ("Fruit Sales")

Set wdApp = Nothing Set wdRng = Nothing End Sub

Figure 16.10

Use bookmarks to quickly enter text into a Word document.

Figure 16.10

Use bookmarks to quickly enter text into a Word document.

0 0

Post a comment