Excel Macro opens new Word document and populates my bookmarks except for the cells containing formulas

Gordo24

New Member
Joined
Apr 19, 2011
Messages
43
Excel is my source document and Word is my template. I have put together a macro in Excel which opens my Word template and populates my bookmarks with the applicable Excel cells. My Excel document is mostly percentages which I am transferring to Word. While I was drafting my source document I was hard coding my percentages in temporarily (e.g. 30.00%, 40.00%, etc) to get it working. Well my "draft" Excel document works perfectly, but when I moved my "draft" Excel document into a "live" working document I replaced my temporary hard coded percentages into formulas which give me my percentages. Of course my macro doesn't work now.

My assumption is the code I put together in my "draft" is not populating my Word bookmarks due to the formulas I added to my Excel cells. I'm also guessing this is not a new problem and hopefully there is an easy fix that I am just not thinking of. I have pasted my code below. Any suggestions would be greatly appreciated.

Sub createTemplate()
On Error GoTo errorHandler
Dim wdApp As Word.Application
Dim myDoc As Word.Document
Dim mywdRange As Word.Range
Dim Wal_Cat_B As Excel.Range
Dim Wal_Cat_D As Excel.Range

Set wdApp = New Word.Application
With wdApp
.Visible = True
.WindowState = wdWindowStateMaximize
End With
Set myDoc = wdApp.Documents.Add(Template:="C:\Test.doc")
Set Wal_Cat_B = Sheets("Sheet1").Range("B2")
Set Wal_Cat_D = Sheets("Sheet1").Range("B3")

With myDoc.Bookmarks
.Item("Wal_Cat_B").Range.InsertAfter Wal_Cat_B.Text
.Item("Wal_Cat_D").Range.InsertAfter Wal_Cat_D.Text

End With

errorHandler:
Set wdApp = Nothing
Set myDoc = Nothing
Set mywdRange = Nothing
End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Ok, I checked into my issue a bit more. I tested my "draft" document by using formulas in the cells to get my percentages just like my "live" document uses and it works just fine. Also, I took my "live" document and hard coded percentages in and it still didn't populate my bookmarks. The template opens, my book marks don't fill. Could there be a step in my "live" document I am missing?? I checked my cells numerous times to ensure they are point to the correct bookmark and they are. I'll continue on, but thought I would put that out there in case it's something simple!
 
Upvote 0
Re: Excel Macro opens new Word document and populates my bookmarks except for the cells containing formulas- RESOLVED

Resolved!!
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,711
Members
452,939
Latest member
WCrawford

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