Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB app with Word bookmark problem

Status
Not open for further replies.

GhostWolf

Programmer
Jun 27, 2003
290
US
I've created a VB app to open a Word document and update it, (using bookmarks), with data retrieved from an As/400. (Not all bookmarks are updated during execution.)

It works fine on the first run, but attempting to open/update the document a second time gives "Run-time error 5102: You entered multiple destinations for a page, line, footnote, endnote or comment" when the program attempts to point to the first bookmark for update.

Since this is my first attempt at something like this, I'm sure there's something I've missed prior to closing the document after the first update.

Any pointers will be greatly appreciated.

Code:
        Set WordApp = CreateObject("Word.Application")
        Set WordDoc = WordApp.Documents.Open(App.Path + "\ElOff.doc")
        While Not .EOF
            updKey = Trim(!ELKEY)
'Build update string            
            Set wdRange = WordDoc.GoTo(what:=wdGoToBookmark, Name:=updKey)    ' <<<<< ERROR generated here <<<<<
            wdRange.Select
            WordApp.Selection.TypeText Text:=updString
            
            If Not InList(Left(updKey, 2)) Then
' Build second update string
                updKey = Trim(updKey) + "e"
                On Error GoTo GetNext
                Set wdRange = WordDoc.GoTo(what:=wdGoToBookmark, Name:=Trim(updKey))
                wdRange.Select
                WordApp.Selection.TypeText Text:=updString
            End If
GetNext:
            .MoveNext
        Wend
        .Close

        updKey = "UpdDate"
        updString = "Updated: " + Format(Now, "mm-dd-yyyy")
        Set wdRange = WordDoc.GoTo(what:=wdGoToBookmark, Name:=Trim(updKey))
        wdRange.Select
        WordApp.Selection.TypeText Text:=updString

        Set wdRange = Nothing
        WordDoc.Save
        WordDoc.Close
    End With

 
I know this is a VB Application, but you just might get a better response on the VBA forum. So, if you don't get an adequate response here, you might try that forum. :)
 
For reference, the thread at the VBA forum is thread707-1206855
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top