Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Visual Basic ( VB ) (http://www.go4expert.com/forums/visual-basic/)
-   -   losing word bookmarks using vbscript (http://www.go4expert.com/forums/losing-word-bookmarks-using-vbscript-t17729/)

JoeFerraro 28May2009 19:00

losing word bookmarks using vbscript
 
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



All times are GMT +5.5. The time now is 20:05.