Updating Word Bookmarks with Inputs from Excel

gtgole

New Member
Joined
Apr 8, 2014
Messages
3
Hi,

I'm hoping that someone can suggest a solution to the following problem:

I have a series of letter templates in Word (around 70 or so), that largely stay the same, but have certain fields that need to be regularly updated. Many of the fields that need to be updated have multiple instances throughout one or more of the templates.

I set up an Excel spreadsheet with a list of all of the fields that ever need to be updated in the templates. As a test, I went through just one of the templates and set the initial instance of 3 fields to be updated as Bookmarks. I then replaced all subsequent instances of each field to be updated as Cross-references to the relevant Bookmark. I attempted to write a macro in the Excel workbook to open the relevant Word template, set each of the Bookmarks to the corresponding value from the Excel worksheet, and then "Update Field" for all Cross-references in the document, so that all updates to the Bookmarked fields would flow through to the other instances of those fields in the document.

Here is my macro so far:

Sub importdatafromexcel()

Dim temp_file As String
Dim save_doc_as As String
Dim excel_input As Worksheet
Dim wordApp As Object

Set wordApp = CreateObject("word.application")
Set excel_input = Worksheets("Sheet1")

temp_file = "filepath"
save_doc_as = "filepath"

With wordApp

.Visible = True
.Documents.Add Template:=(temp_file)

Set wordDoc = .activedocument


wordDoc.bookmarks("Bookmark1").Select
.Selection.InsertAfter (excel_input.Cells(3, 16))
wordDoc.bookmarks("Bookmark2").Select
.Selection.InsertAfter (excel_input.Cells(3, 17))
wordDoc.bookmarks("Bookmark3").Select
.Selection.InsertAfter (excel_input.Cells(3, 18))

End With

wordApp.activedocument.SaveAs Filename:=save_doc_as

End Sub


The macro works all the way through, and even highlights the relevant bookmarks, but doesn't replace the bookmark text with the input text from Excel. Does anyone have any idea how to make this work? Also does anyone know how to update all the cross-references once the bookmark has been updated?

Any help would be greatly appreciated!

Thanks
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Forum statistics

Threads
1,216,796
Messages
6,132,742
Members
449,756
Latest member
AdkinsP

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top