PDA

View Full Version : VBA code in Excel opens Word template and fills bookmarks, but can't get correct form



ymrpttr
08-29-2016, 02:40 PM
I am using an excel worksheet and using VBA to access a .dot template. Both files have the bookmarks, data is transfered correctly. I am using placeholder bookmarks, the one that looks like a beam I.


My only problem is how to get the correct format in the Word document.


Example: The bookmark in excel shows 0.71 however the bookmark in word is displaying 0.712669683257918.


How can I get the bookmark to display only 2 decimals in word or exactly display the same value and format as the bookmark in excel?


Below is the code in the macro for reading and sending the value in the bookmark.


dottempplate.Bookmarks(xlName.Name).Range.Text = Range(xlName.Value)


Thanks


Yomero

gmaxey
08-29-2016, 04:27 PM
dottempplate.Bookmarks(xlName.Name).Range.Text = Format(Range(xlName.Value), "#.00")

ymrpttr
08-29-2016, 04:52 PM
Perfect! Thank You! Thank you! Thank You!....