Please help!
I am new to VBA, and I need help to make the following macro to import from XL ("Sheet2 ") multiple tables 1,2,3..., import them to a specific Wd doc Bookmarks 1, 2, 3, each table from sheet2 linked to one Bookmark from Wd doc.
Based on the macro attached I managed to bring only the first table from Sheet2 and copy to designated spot Bookmark2. Now I need to bring the next table (e.g. III.1 table below) an copy-it to Wd Bookmark3, and so on.
One way, maybe set macro to search the specific text above table (e.g. Chapter III.1), and import only the table below that text.
NOTE: In Wd doc "Fisa.docx" I have infomation that I dont want to be erased when the tables are imported from Exl. Thank you!
[/IMG]
I am new to VBA, and I need help to make the following macro to import from XL ("Sheet2 ") multiple tables 1,2,3..., import them to a specific Wd doc Bookmarks 1, 2, 3, each table from sheet2 linked to one Bookmark from Wd doc.
Based on the macro attached I managed to bring only the first table from Sheet2 and copy to designated spot Bookmark2. Now I need to bring the next table (e.g. III.1 table below) an copy-it to Wd Bookmark3, and so on.
One way, maybe set macro to search the specific text above table (e.g. Chapter III.1), and import only the table below that text.
NOTE: In Wd doc "Fisa.docx" I have infomation that I dont want to be erased when the tables are imported from Exl. Thank you!
Code:
[/COLOR]Sub ExportExcelDataToWordDocument2()
'Dim wdExcelApp As Application 'Excel is the default library (optional)
Dim wdWordApp As Word.Application 'Word app
Application.ScreenUpdating = False
' Creating a new instance of Word
Set wdWordApp = New Word.Application 'instantiate a new instance of Word 2010
With wdWordApp
' Making Word Visible on the screen
.Visible = True 'iff false, document is invisible.
.Activate ' make it the top pane, bring it to the front.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' create a new Word Document based on the specified template
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
.Documents.Add "C:\Users\stefan.georgescu\Desktop\Fisa.dotm"
'as before, copy the whole table from sheet to clipboard.
Sheet2.Activate
Range("A1", Range("A1").End(xlDown).End(xlToRight)).Copy
.Selection.GoTo what:=-1, Name:="bookmark2" ' -1 means "wdgotobookmark"
.Selection.Paste 'paste from the clipboard to the Word Doc.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Save WORD Document
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim TheFileName As String
TheFileName = "C:\Users\stefan.georgescu\Desktop\Fisa.docx"
'(SaveAs is for Office 2003 and earlier - deprecated)
.ActiveDocument.SaveAs2 TheFileName
'replaces existing .doc iff exists
' Close Documents and Quit Word
.ActiveDocument.Close 'close .DOCx
.Quit 'exit Word
End With
Application.ScreenUpdating = True
'MEMORY CLEANUP
Set wdWordApp = Nothing 'garbage collection
'Set wdExcelApp = Nothing 'OPTIONAL
End Sub
[COLOR=#2A2E2E]