PDA

View Full Version : copy from excel to word



lior03
01-15-2006, 12:22 AM
hello
is there a way to turn an excel workbook into a word document?.
thanks

Ken Puls
01-15-2006, 12:42 AM
Uh... turn it into a word document, no.

But if you wanted to copy data from Excel to Word, that can be done. Are you looking to copy over tables, just specific ranges, or everything that's in your workbook?

lior03
01-15-2006, 01:07 AM
hello
i want to copy a range of cells into a word documents .
it mat be a table of data.
could it be doen through vba?
thanks

Ken Puls
01-15-2006, 01:25 AM
Put this into an Excel module:

Sub PushSelectionToWord()
Dim wdApp As Object
Set wdApp = GetObject(, "Word.Application")
Selection.Copy
wdApp.Selection.Paste
Set wdApp = Nothing
End Sub

Make sure that you only have one instance of Word running, and place the insertion point exactly where you want the data to come in. Save it before you run the macro, just in case you don't like what happens, though. :)

Go back to Excel, select the range of cells you want to send over, and run the macro.

It will create a table in Word of the cells you selected.

HTH,

lior03
01-15-2006, 02:18 AM
hello

thanks for the macro.what about updating the word document if my excek sheet hase changed assumig both are open.
thanks again

Ken Puls
01-15-2006, 02:23 AM
Well, the easy way would be to delete the stuff that was inserted by the macro and run it again. In this case, there isn't really an easy way to identify what came from the macro, and what didn't...

TonyJollans
01-15-2006, 04:00 AM
Hi moshe,

What are you trying to achieve here?

Your original question asked about 'changing a workbook'. Ken's code copies the Selection, which may be just a part of a workbook.

If you want a Word document which reflects the latest version of a workbook, what about embedding a link to it rather than copying the contents?

fumei
03-31-2006, 08:47 AM
Makes sense to me.