copy-paste tables from word to excel

ε祈祈猫儿з 提交于 2019-12-01 08:05:29

Something like this:

Sub read_word_document()

Const DOC_PATH As String = "Z:\mydir\myfile1.DOC"

Dim sht As Worksheet
Dim WordDoc As Word.Document
Dim WordApp As Word.Application
Dim i As Long, r As Long, c As Long
Dim rng As Range, t As Word.Table

    Set WordApp = CreateObject("Word.Application")
    WordApp.Visible = False
    Set WordDoc = WordApp.Documents.Open(DOC_PATH, ReadOnly:=True)

    Set sht = Sheets("Temp")
    Set rng = sht.Range("A1")
    sht.Activate

    For Each t In WordDoc.Tables
        t.Range.Copy
        rng.Select
        rng.Parent.PasteSpecial Format:="Text", Link:=False, _
                    DisplayAsIcon:=False
        With rng.Resize(t.Rows.Count, t.Columns.Count)
            .Cells.UnMerge
            .Cells.ColumnWidth = 14
            .Cells.RowHeight = 14
            .Cells.Font.Size = 10
        End With

        Set rng = rng.Offset(t.Rows.Count + 2, 0)
    Next t
    WordDoc.Close
    WordApp.Quit
End Sub
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!