VBA在word中将表从excel复制到word

时间:2018-06-15 05:24:18

标签: excel vba ms-word

我面临的问题是代码对我来说很好。但是当我尝试在其他一些用户系统中使用代码时,代码不会复制表并粘贴它,代码会复制用户的最后一个ctrl-C实例并将其粘贴到word文件中。有什么建议吗?这是完整的代码:

Sub GetTable()

    Dim oXL As Excel.Application
    Dim wb1 As Excel.Workbook
    Dim WorkbookToWorkOn As String
    Dim ExcelWasNotRunning As Boolean
    Dim i As Integer

    On Error Resume Next
    Set oXL = GetObject("Excel.Application")

    If Err Then
       ExcelWasNotRunning = True
       Set oXL = CreateObject("Excel.Application")
    End If


    Set wb1 = oXL.Workbooks.Open("**.xlsx")

    wb1.Sheets("Tables for Report").Range("N3:AB49").Copy
    Selection.Collapse Direction:=wdCollapseStart
    Selection.Paste

    Selection.Tables(1).Columns(1).SetWidth ColumnWidth:=136.5, RulerStyle:= _
    wdAdjustNone

    For i = 1 To 3
        Selection.Tables(1).Rows(i).Shading.Texture = wdTextureNone
        Selection.Tables(1).Rows(i).Shading.ForegroundPatternColor = wdColorAutomatic
        Selection.Tables(1).Rows(i).Shading.BackgroundPatternColor = 15986394
    Next



    oXL.Quit
    Set oXL = Nothing


End Sub

0 个答案:

没有答案