Page 1 of 1

Copy word table to excel

Posted: Thu Nov 19, 2020 10:25 pm
by sna
Hi Dear,

I need to copy from table word doc to excel .
I used this code form google but not working.
fine,I need to copy all table in word to a single sheet in excel.

I upload the file

Thanks

Re: Copy word table to excel

Posted: Thu Nov 19, 2020 10:55 pm
by snasui
:D The example code is below:

Code: Select all

'Other code
With wdDoc
    For t = 1 To .Tables.Count
        Set xlWkSht = Sheets("Menu")
        .Tables(t).Range.Copy
        With xlWkSht
            If .Range("a1").Value = "" Then
                .Paste .Range("A1")
            Else
                .Paste .Range("a" & .Rows.Count).End(xlUp).Offset(1, 0)
            End If
            c = .UsedRange.Columns.Count
            r = .UsedRange.Columns.Count
            .Range("A1:" & .Cells(r, c).Address).WrapText = False
        End With
    Next t
End With
'Other code

Re: Copy word table to excel

Posted: Fri Nov 20, 2020 8:23 am
by sna
I test the code it is working but not completely copied tables

Re: Copy word table to excel

Posted: Fri Nov 20, 2020 7:17 pm
by snasui
:D Please post the correct result for easy to compare and fix VBA code.

Re: Copy word table to excel

Posted: Fri Nov 20, 2020 10:34 pm
by sna
I test it again it works but not fit column width

Re: Copy word table to excel

Posted: Fri Nov 20, 2020 10:45 pm
by snasui
:D The example code is below:

Code: Select all

'Other code
With xlWkSht
    If .Range("a1").Value = "" Then
        .Paste .Range("A1")
    Else
        .Paste .Range("a" & Rows.Count).End(xlUp).Offset(1)
    End If
    .UsedRange.WrapText = False
    .UsedRange.EntireColumn.AutoFit
    .UsedRange.EntireRow.AutoFit
End With
'Other code

Copy word table to excel

Posted: Fri Nov 20, 2020 10:52 pm
by sna
Thank you 🙏