Hello All,
Can anyone advise on copying and pasting from excel to word.
Many thanks
yours,
Ed
Hello All,
Can anyone advise on copying and pasting from excel to word.
Many thanks
yours,
Ed
What do you need, specifically? I can normally copy from Excel and paste to Word quite easily...
Regards,
Patrick
I wept for myself because I had no PivotTable.
Then I met a man who had no AutoFilter.
Microsoft MVP for Excel, 2007 & 2008
Thanks for you reply.
I apologies for not being clear.
I would like to know the VBA code to copy and paste infomation from excel to word.
Many thanks
yours,
Ed
OK, a true copy-paste between apps using code is tricky.
Can you describe what you need to do in some detail?
Regards,
Patrick
I wept for myself because I had no PivotTable.
Then I met a man who had no AutoFilter.
Microsoft MVP for Excel, 2007 & 2008
Office applications come with a very handy tool called the Macro Recorder. Turn it on, then do manually what you want to do in code. The recorded code isn't perfect, because it captures a lot of mouse actions, such as activating and selecting objects, which are not strictly required. But it will get you started, and it will help with syntax.Originally Posted by photon_ed
Go to Excel, turn on the macro recorder, and copy what you need to copy. Go to Word, turn on the macro recorder, and paste what you need pasted. You'll have to get some code to get Excel to work with the Word application; this might be a good place to start:
http://peltiertech.com/Excel/XL_PPT.html
Use the Excel code you recorded, and the Word code, keeping in mind that the Word code will need to be prefixed with a reference to the Word application, document, or other Word object.
- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com
_______
for a range:
[VBA]
Sub CopyToWord()
'This code requires a referece to the Word object model
Dim Appword As New Word.Application
Dim wdDoc As Word.Document
Set Appword = CreateObject("Word.Application")
Appword.Documents.Add
Range("A15:B36").Copy
Appword.Selection.Paste
Appword.Visible = True
End Sub
[/VBA]
Steve
"Nearly all men can stand adversity, but if you want to test a man's character, give him power."
-Abraham Lincoln
Many thanks for all the responds.
Lucas: Visual Basic doesnt seem to like the line " Dim Appword As New Word.Application " and a popup message saying "Compile error: User-defined type not defined".
Pelase advise.
yours,
Ed
Hi Ed
You need to add a reference to Word in the VBE as the Comment line in the code states.
Tools/References Microsoft Word xx Object Library.
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
That is perfect!
Many thanks to ALL.
yours,
Ed
Ed,Originally Posted by photon_ed
As Malcolm indicated, you needed to set a reference. You could have also used late binding, and eliminated the need to set a reference. (Late binding is especially useful if you think people with different versions of Word will use the code, as this can cause version conflicts if you use early binding.)
[VBA]
Sub CopyToWord()
'This code requires a referece to the Word object model
Dim Appword As Object 'Word.Application
Set Appword = CreateObject("Word.Application")
Appword.Documents.Add
Range("A15:B36").Copy
Appword.Selection.Paste
Appword.Visible = True
Set Appword = Nothing
End Sub
[/VBA]
Regards,
Patrick
I wept for myself because I had no PivotTable.
Then I met a man who had no AutoFilter.
Microsoft MVP for Excel, 2007 & 2008