jppinto
asked on
Copy values from Excel cells into Word
Hello,
I need to automate a task of copying values from 4 cells in an Excel sheet into a Word template. It could be when the user clicks a button on the Excel sheet that the macro copies the values from these 4 sheets into specific places on the Word document.
What is, in your opinion, the best way of doing it? Create a link between the two documents or, using a macro, copy the values into the Word file? Can you please post an example on how to do it with a macro?
Thanks in advance for your help.
jppinto
I need to automate a task of copying values from 4 cells in an Excel sheet into a Word template. It could be when the user clicks a button on the Excel sheet that the macro copies the values from these 4 sheets into specific places on the Word document.
What is, in your opinion, the best way of doing it? Create a link between the two documents or, using a macro, copy the values into the Word file? Can you please post an example on how to do it with a macro?
Thanks in advance for your help.
jppinto
ASKER
Hi Andrew,
Thanks for your help. I get an user defined type error on this line:
Dim rng As word.Range
Can you see what's wrong?
Regards,
jppinto
Thanks for your help. I get an user defined type error on this line:
Dim rng As word.Range
Can you see what's wrong?
Regards,
jppinto
ASKER
I've tryed changing to just this:
Dim rng As Range
made some modification to your code and it's working. But I have a problem with the format of the numbers that are being passed into Word. The values are currency (£) but I can't seem to pass the values on the correct formatting.
Dim rng As Range
made some modification to your code and it's working. But I have a problem with the format of the numbers that are being passed into Word. The values are currency (£) but I can't seem to pass the values on the correct formatting.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excelent work Andrew! VBA is not my strongest skills! ;)
At the moment the macro keeps the Word doc open so you can see, but it could save and close if that's what you want. This is a VBA solution that does what you asked. It is also possible to have pasted links into Word that can be updated when you want, using copy then paste special...paste links, but this puts the overhead of OLE linking on the files. I generally find it cleaner to copy once using VBA, then just the values are there with no residual link between the files.
word-copy.xlsm
From-Excel.docx