vba copy from word table to excel

前端 未结 1 1198
暗喜
暗喜 2021-01-15 04:45

I\'m trying to generate an excel file with 5 column from specific tables\' cells in a word file (copy from word table to excel). My word file has 280 tables. I have no probl

相关标签:
1条回答
  • 2021-01-15 05:10

    After some review, i;ve found that i shoud use pastespecial in my paste the corrected code is bellow

    Sub copyfromwordtoexcel()
    Dim exApp As Excel.Application
    Dim exDoc As Excel.Workbook
    Set exApp = CreateObject("Excel.Application")
    Set exDoc = exApp.Workbooks.Add
    For xx = 1 To ActiveDocument.Tables.Count
    On Error Resume Next
    If ActiveDocument.Tables(xx).Columns.Count = 2 Then
    
    ActiveDocument.Tables(xx).Cell(2, 2).Range.Copy
    exApp.Visible = True
    Cells(xx, 1).Select
    ActiveSheet.PasteSpecial (xlPasteAll)
    
    Application.Visible = True
    exApp.Visible = False
    ActiveDocument.Tables(xx).Cell(3, 2).Range.Copy
    exApp.Visible = True
    Cells(xx, 2).Select
    ActiveSheet.PasteSpecial (xlPasteAll)
    i = ActiveDocument.Tables(xx).Rows.Count
    ActiveDocument.Tables(xx).Cell(i - 2, 2).Range.Copy
    exApp.Visible = True
    Cells(xx, 3).Select
    ActiveSheet.PasteSpecial (xlPasteAll)
    Application.Visible = True
    ActiveDocument.Tables(xx).Cell(i - 1, 2).Range.Copy
    exApp.Visible = True
    Cells(xx, 4).Select
    ActiveSheet.PasteSpecial (xlPasteAll)
    Application.Visible = True
    ActiveDocument.Tables(xx).Cell(i, 2).Range.Copy
    exApp.Visible = True
    Cells(xx, 5).Select
    ActiveSheet.PasteSpecial (xlPasteAll)
    Application.Visible = True
    exApp.Visible = True
    End If
    
    Next
    

    End Sub

    0 讨论(0)
提交回复
热议问题