![]() |
Checking for bookmarks in Word document
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_License e) Then WordApp.ActiveDocument.Bookmarks("BM_Licensee").Ra nge.InsertAfter Txt_Licensee End If end with |
Checking for bookmarks in Word document
Without any testing at all, the first thing I would try is to enclose
the "BM_Licensee" in quotes in the If statement. In article , jag wrote: 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_License e) Then WordApp.ActiveDocument.Bookmarks("BM_Licensee").Ra nge.InsertAfter Txt_Licensee End If end with |
Checking for bookmarks in Word document
Thanks, this was it.... Sorry I overlooked somthing as
simple as this... Thanks again... "JE McGimpsey" wrote: Without any testing at all, the first thing I would try is to enclose the "BM_Licensee" in quotes in the If statement. In article , jag wrote: 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_License e) Then WordApp.ActiveDocument.Bookmarks("BM_Licensee").Ra nge.InsertAfter Txt_Licensee End If end with |
All times are GMT +1. The time now is 05:09 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com