1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

losing word bookmarks using vbscript

Discussion in 'Visual Basic ( VB )' started by JoeFerraro, May 28, 2009.

  1. JoeFerraro

    JoeFerraro New Member

    Joined:
    May 28, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    I have a word document that has some bookmarks within it. I want to go to a bookmark and modify some of the text and then save the document. The editting is working but after saving the document when I reopen the bookmarks are gone. The file is saved out to a new document if that makes any difference.

    Here is a sample of the code I am using. I am not using this from within word as you can see where I launch the word application within the vbscript code.

    Thanks for any help.


    Code:
    Set oWord = CreateObject("Word.Application")
    Set doc = oWord.documents.Open ("$(FilepathToConvert)")
    on error resume next
    
    Dim wdReplaceAll
    wdReplaceAll = 2
    
    Dim wdGoToBookmark
    wdGoToBookmark = -1 
     
    Dim cvArray
    cvArray = Split("$(cv)", ",")
    
    oWord.Selection.GoTo wdGoToBookmark,,"$(bookmark 1)"
    doc.Bookmarks("$(bookmark 1)").Select
    for Each item in cvArray
      With oWord.Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = item
        .Replacement.Text = item
        .Forward = True
        .Replacement.Font.Bold = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .CorrectHangulEndings = True
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = False
        .MatchFuzzy = False
        .Execute , , , , , , , , , , wdReplaceAll 
      End With
    Next
    
    Dim delArray
    delArray = Split("$(deleteItems)", ",")
    
    for Each item in delArray
      With oWord.Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = item
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .CorrectHangulEndings = True
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = False
        .MatchFuzzy = False
        .Execute , , , , , , , , , , wdReplaceAll 
      End With
    Next
    
    doc.SaveAs "$(ConvertedPath)"
    doc.Close False
    Set doc = Nothing
    oWord.quit
    Set oWord = Nothing
     
    Last edited by a moderator: May 28, 2009

Share This Page