Checking for bookmarks in Word document

J

jag

I have a spreadsheet that the users fills in several fields, etc. then clicks a button to print a report. The report is a Word template file that has several bookmarks set where the data should be populated. I want to check for the existance of the bookmark in the document and update it if it exist in the document, (I have several reports and want to use the same procedure for all, but all reports will not have all the bookmarks). The code is listed below. My problem when the code runs, the template file is opened, but the bookmarks are not updated. The if statement checking for the bookmark runs and skips the bookmark as if it is not there. I can remove the if statement and the bookmark is updated. What have I done wrong in my coding.... Any help is appreciated.

Dim WordApp As Word.Application
Set WordApp = New Word.Application

Call Get_Excel_Info
With WordApp
.Visible = True
.Documents.Add Template:=TemplatePath & TemplateToOpen, newtemplate:=False
.Application.WindowState = wdWindowStateMaximize
If .ActiveDocument.ProtectionType <> wdNoProtection Then
.ActiveDocument.Unprotect Password:=""
End If
If WordApp.ActiveDocument.Bookmarks.Exists(BM_Licensee) Then
WordApp.ActiveDocument.Bookmarks("BM_Licensee").Range.InsertAfter Txt_Licensee
End If
end with
 
J

JE McGimpsey

Without any testing at all, the first thing I would try is to enclose
the "BM_Licensee" in quotes in the If statement.
 
J

jag

Thanks, this was it.... Sorry I overlooked somthing as
simple as this...

Thanks again...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top