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
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