Pages

Monday, August 22, 2011

Copy all tables from a word document to Excel Using VBA

Macro to copy all tables from a word document to Excel 

Sub import_word_tables()
    Dim objWord As Object
    Dim objdoc As Object
    Dim i As Integer
    Dim wkb As Workbook
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = True
    Set objdoc = objWord.Documents.Open("C:\Users\ADMIN\Desktop\sample files\sample.docx")
        
        For i = 1 To objdoc.Tables.Count
            objdoc.Tables(i).Range.Copy
            ThisWorkbook.Sheets(1).Select
            Range("a1048576").End(xlUp).Offset(2, 0).Select
            ActiveSheet.Paste
        Next
    
    objdoc.Close
    objWord.Quit
    Set objdoc = Nothing
    Set objWord = Nothing
End Sub


No comments:

Post a Comment