Excel VBA to Word bookmark with Excel cell format retained -
i have vba code snippet extracts excel cell data word template, using bookmarks in template assign values specific template locations. able export excel cell values in text format bookmarks, cannot retain native excel formatting.
the code uses .value property extract data in text formatting. i'm trying minimize manual formatting second time in word (converting text exported value of 150001.22 dent_90 excel range $150,001.22 dent_90 bookmark in word, example).
any idea on how might done, such can export word using excel currency cell formatting? i've looked @ explanations formattext, can't seem work following snippet:
sub testmemogen() dim objword object dim ws2 worksheet application.screenupdating = false set ws2 = thisworkbook.sheets("word export") set objword = createobject("word.application") objword.visible = true objword.documents.open "c:\users\ tester\word test sim.docm" objword.activedocument .bookmarks("dent_90").range.text = ws2.range("dent_90").value end set objword = nothing application.enableevents = true end sub
thanks , suggestions. have hundred bookmarks linked different templates, huge if formatting can exported natively excel.
.value "text" of cell, in case number. doesn't carry formatting info it. need numberformat.
<some number> = ws2.range("dent_90").value <the format> = ws2.range("dent_90").displayformat.numberformat
a little test shows:
sub junk() msgbox "format=" & application.range("g2").displayformat.numberformat end sub
so, info excel cell "format=#,##0".
in word doc, can use format() described above scott, or at: https://msdn.microsoft.com/en-us/library/office/gg251755.aspx
as side note, did know can try things , record functions in macro go? then, @ recorded macro see how things, perhaps formatting text entered, gives little more control on precise formatting...
Comments
Post a Comment