Sunday, April 20, 2014

Copy all tables from word document to separate worksheets

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
    Set objdoc = Nothing
    Set objWord = Nothing

End Sub

No comments:

Post a Comment

Import data from SQL

Macro to import data from SQL using ADO connection string: Sub Import_data_from_SQL() ' Tools -> References -> Microsoft Active...