[Asm] 纯文本查看 复制代码
Sub Macro1()'引用Microsoft Word 12.0 Object Library Dim MyWord As New Word.Application Dim arr, MyPath$, MyFile$, MyName$, i& MyPath = ThisWorkbook.Path & "\" MyFile = MyPath & "进货表.docx" arr = [a1].CurrentRegion With MyWord .Visible = False For i = 2 To UBound(arr) Step 2 MyName = MyPath & "进货表(" & arr(i, 10) & ").docx" FileCopy MyFile, MyPath & "进货表(" & arr(i, 10) & ").docx" .Documents.Open MyName With .ActiveDocument.Tables(2) .Cell(6, 2).Range.Text = Chr(13) & arr(i, 10) & Chr(13) .Cell(12, 2).Range.Text = Chr(13) & Mid(arr(i, 2), 5, 2) .Cell(12, 3).Range.Text = Chr(13) & Right(arr(i, 2), 2) .Cell(12, 4).Range.Text = Chr(13) & Left(arr(i, 2), 4) .Cell(12, 6).Range.Text = Chr(13) & Mid(arr(i + 1, 2), 5, 2) .Cell(12, 7).Range.Text = Chr(13) & Right(arr(i + 1, 2), 2) .Cell(12, 8).Range.Text = Chr(13) & Left(arr(i + 1, 2), 4) .Cell(15, 1).Range.Text = arr(i, 2) & " " & arr(i, 3) & arr(i, 4) & " " & arr(i, 5) & " " & arr(i, 6) & " 到" .Cell(16, 1).Range.Text = arr(i + 1, 2) & " " & arr(i + 1, 3) & arr(i + 1, 4) & " " & arr(i + 1, 5) & " " & arr(i + 1, 6) End With .ActiveDocument.Close True Next .Quit End With Set MyWord = Nothing MsgBox "ok"End Sub