Quantcast
Channel: Excel VBA Codes & Macros
Viewing all articles
Browse latest Browse all 52

Copy all tables from word document to separate worksheets

$
0
0
Macro to copy all tables from word document to separate worksheets -

Sub import_word_tables_to_seperate_sheet()
    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") ' choose word document
        
        For i = 1 To objdoc.Tables.Count
            objdoc.Tables(i).Range.Copy ' copy tables
            ThisWorkbook.Sheets.Add(after:=Sheets(Sheets.Count)).Name = "Table_"& i ' add new sheet
            Range("a1").Select ' paste table
            ActiveSheet.Paste
        Next
    
    objdoc.Close
    objWord.Quit
    Set objdoc = Nothing
    Set objWord = Nothing

End Sub


Viewing all articles
Browse latest Browse all 52

Trending Articles