ferret
03-15-2011, 09:41 AM
Hi all, thanks for the help you have given me so far as a guest...much appreciated. I'm still on the steep learning curve for vba and am trying to take a step further.
I have an excel spreadsheet with data in small range of cells (c2:d7) [I have tried keeping all range references the same but still have the problem]. I want to transfer that data into an existing word document keeping it's 'table' layout, and save the document using a new file name and location.
So far, my journey has taught me how to open the word document. I have looked at a few of the scripts you have already posted to eg paste the cells as a inline object, or cross reference from named cells to bookmarks. I can see the logic being followed but my scripts are falling over at the same place... I open the document, grab the data from the spreadsheet and get a 5941 error when I try to insert it into word.
I have ensured that there is a reference to the Microsoft Office 14 word object library... but I don't understand about 'objects'
For instance I have tried this code from another thread 'Open the word document
Set wdApp = CreateObject("Word.Application")
wdApp.Documents.Open openthisfile
wdApp.Visible = True
'copy cells
Worksheets(1).Range("c2:d7").Select
Selection.Copy
'insert cells
wdApp.ActiveDocument.InlineShapes(1).Activate
Range("A1:B6").Select
ActiveSheet.Paste
Application.CutCopyMode = False
'openthisfile' is a string variable which sets the filepath and it opens ok
it falls over 4 lines from the end;
wdApp.ActiveDocument.InlineShapes(1).Activate
which is highlighted with the error when I debug...
Your help will be much appreciated.
Cheers
I have an excel spreadsheet with data in small range of cells (c2:d7) [I have tried keeping all range references the same but still have the problem]. I want to transfer that data into an existing word document keeping it's 'table' layout, and save the document using a new file name and location.
So far, my journey has taught me how to open the word document. I have looked at a few of the scripts you have already posted to eg paste the cells as a inline object, or cross reference from named cells to bookmarks. I can see the logic being followed but my scripts are falling over at the same place... I open the document, grab the data from the spreadsheet and get a 5941 error when I try to insert it into word.
I have ensured that there is a reference to the Microsoft Office 14 word object library... but I don't understand about 'objects'
For instance I have tried this code from another thread 'Open the word document
Set wdApp = CreateObject("Word.Application")
wdApp.Documents.Open openthisfile
wdApp.Visible = True
'copy cells
Worksheets(1).Range("c2:d7").Select
Selection.Copy
'insert cells
wdApp.ActiveDocument.InlineShapes(1).Activate
Range("A1:B6").Select
ActiveSheet.Paste
Application.CutCopyMode = False
'openthisfile' is a string variable which sets the filepath and it opens ok
it falls over 4 lines from the end;
wdApp.ActiveDocument.InlineShapes(1).Activate
which is highlighted with the error when I debug...
Your help will be much appreciated.
Cheers