Moving data from excel to Word

artikox

New Member
Joined
Jan 31, 2021
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hello
I would like to move a number from excel to word with decimal number formatting, like 10.00
I have tried with this program but the number moved to word is 10 and not 10.00, please could someone help me?
Thank you
-------------------------------------------------------------------
Sub ExcelToWord()
Dim objWord As Object
Dim ws As Worksheet

Set ws = ThisWorkbook.Sheets("Sheet1")
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
objWord.Documents.Open "C:\New\Test.docx"
With objWord.ActiveDocument

.Bookmarks("Book1").Range.Text = ws.Range("A1").Value ' value in A1 is 10.00

End With
Set objWord = Nothing

End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi artikox. You should be able to format a number by...
Code:
.Bookmarks("Book1").Range.Text = FormatNumber(ws.Range("A1").Value, 2)
Also, you need to save and close the document, then Quit the ObjWord application (ie. objWord.Quit) before you set the objWord application to Nothing. HTH. Dave
ps. please use code tags
 
Upvote 0
Hi NdNoviceHlp, thank you so much for your elegant suggestion
I have found another solution that seems to work
.Bookmarks("Book1").Range.Text = Format (ws.Range(Cells(1, 1), Cells(1, 1)).Value, "#,##0.00") this is a general Range formula applied on a single cell a bit unorthodox...

 
Upvote 0

Forum statistics

Threads
1,215,263
Messages
6,123,958
Members
449,135
Latest member
jcschafer209

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