Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

excel to word formatting problem 1

Status
Not open for further replies.

pookie312

MIS
Jun 9, 2004
14
0
0
US
I wrote a program to copy info from excel and put it into a word document. The only problem I'm having is keeping the formatting of the numbers. I have the code format the cells in excel and I have the text form fields in word formatted correctly, but when the numbers are transferred, the formatting is lost. Anyone have any ideas on how to fix this??? Thanks.
Here's a bit of the code:

Range("F9:J9").Select
Selection.NumberFormat = "#,##0.00"
Range("G10:K10").Select
Selection.NumberFormat = "#,##0.00"
Range("A1").Select

wdoc.ActiveWindow.Selection.Goto What:=wdGoToBookmark, Name:="PA1"
wdoc.ActiveWindow.Selection.TypeText ActiveSheet.Range("F9")
wdoc.ActiveWindow.Selection.Goto What:=wdGoToBookmark, Name:="PA2"
wdoc.ActiveWindow.Selection.TypeText ActiveSheet.Range("G9")
wdoc.ActiveWindow.Selection.Goto What:=wdGoToBookmark, Name:="PA3"
wdoc.ActiveWindow.Selection.TypeText ActiveSheet.Range("H9")
wdoc.ActiveWindow.Selection.Goto What:=wdGoToBookmark, Name:="PA4"
wdoc.ActiveWindow.Selection.TypeText ActiveSheet.Range("I9")
wdoc.ActiveWindow.Selection.Goto What:=wdGoToBookmark, Name:="PA5"
wdoc.ActiveWindow.Selection.TypeText ActiveSheet.Range("J9")
wdoc.ActiveWindow.Selection.Goto What:=wdGoToBookmark, Name:="PA6"
wdoc.ActiveWindow.Selection.TypeText ActiveSheet.Range("G10")
wdoc.ActiveWindow.Selection.Goto What:=wdGoToBookmark, Name:="PA7"
wdoc.ActiveWindow.Selection.TypeText ActiveSheet.Range("H10")
wdoc.ActiveWindow.Selection.Goto What:=wdGoToBookmark, Name:="PA8"
wdoc.ActiveWindow.Selection.TypeText ActiveSheet.Range("I10")
wdoc.ActiveWindow.Selection.Goto What:=wdGoToBookmark, Name:="PA9"
wdoc.ActiveWindow.Selection.TypeText ActiveSheet.Range("J10")
wdoc.ActiveWindow.Selection.Goto What:=wdGoToBookmark, Name:="PA10"
wdoc.ActiveWindow.Selection.TypeText ActiveSheet.Range("K10")
 
Try using the Format function. For example:
Code:
 wdoc.ActiveWindow.Selection.TypeText ActiveSheet.Range("F9")
would become:
Code:
 wdoc.ActiveWindow.Selection.TypeText Format(ActiveSheet.Range("F9"), "#,##0.00")
Let me know if that does it for you!

VBAjedi [swords]
 
And what about this ?
wdoc.ActiveWindow.Selection.TypeText ActiveSheet.Range("F9").Text

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Even better, PH! I'm so used to using .Formula and .Value that I forget that .Text even exists. . .

VBAjedi [swords]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top