Format Word Bookmark from Excel value

tbeards

New Member
Joined
May 27, 2009
Messages
47
Hi All! This is my very first post to MrExcel. I love this site and have used it countless times to find solutions to my problems. I think I can finally contribute something that I haven't been able to find anywhere on the www; however, I would like to see if anyone can make my code simpler.

My code below will take values in Excel and copy them to bookmarks in a Word template I have created. The problem I could not find was how to format the bookmark so I could see the value in Word as currency, %, etc. I finally figured it out and that is below. My question is, based on my code below, is there an easer way to do this vs. the way I have the various Set BookmarkRange lines? Any advice would be beneficial. I do not have any formal training in VBA or any programming for that matter so any advice is welcome...

~tbeards

Option Explicit
Sub PasteExcelPricingToWord()
Dim obj As Word.Application
Dim wdDoc As Object
Dim LPRMarkdown As Range
Dim StockFee As Range
Dim CustomerName As Range
Dim AccountManager As Range
Dim BookmarkRange As Word.Range
Dim Workbook As ThisWorkbook
'******** NAME THE EXCEL VALUES TO THE BOOKMARK NAMES ***************
Worksheets(constSheetLPR).Activate 'Activate the worksheet
Set LPRMarkdown = Worksheets(constSheetLPR).Range("H19")
Set StockFee = Worksheets(constSheetLPR).Range("H20")
Set CustomerName = Worksheets(constSheetLPR).Range("C4")
Set AccountManager = Worksheets(constSheetLPR).Range("C5")

'***************** OPEN THE WORD PRICING PROPOSAL TEMPLATE ***************
Set obj = CreateObject("Word.Application.11") 'Create a word object
Set wdDoc = obj.Documents.Open("C:\\Documents and Settings\221008334\Desktop\Pricing_Presentation_test.doc")
obj.Visible = True
'************* INPUT THE EXCEL VALUES TO THE BOOKMARKS & FORMAT **********
Set BookmarkRange = wdDoc.Goto(what:=wdGoToBookmark, Name:="Markdown")
BookmarkRange.Text = Format$(LPRMarkdown, "$#,###")
Set BookmarkRange = wdDoc.Goto(what:=wdGoToBookmark, Name:="StockFee")
BookmarkRange.Text = Format$(StockFee, "0.00%")
Set BookmarkRange = wdDoc.Goto(what:=wdGoToBookmark, Name:="CustomerName")
BookmarkRange.Text = CustomerName
Set BookmarkRange = wdDoc.Goto(what:=wdGoToBookmark, Name:="AccountManager")
BookmarkRange.Text = AccountManager
'*************** SAVE THE WORD DOC WITH THE CUSTOMER NAME ****************
wdDoc.SaveAs Filename:="C:\Pricing\" & CustomerName & " Pricing Proposal.doc" 'Save the file
Set obj = Nothing 'Release object
Set wdDoc = Nothing 'Release object
Call MsgBox("Your Pricing Proposal is complete.", vbOKOnly)
PathErr:
Exit Sub
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,214,979
Messages
6,122,552
Members
449,088
Latest member
davidcom

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