我对 VBA 很陌生,我的第一个代码是复制 excel 表并将其粘贴到 word 中。它正在工作,但问题是所有表格都是左对齐粘贴的,我希望它居中对齐。有谁知道该怎么做?将在这里发布我的代码:
Sub excel2word()
Dim objWord As New Word.Application
'Copy the range Which you want to paste in a New Word Document
Set objWord = CreateObject("Word.Application")
For i = 2 To 200
With objWord
.Documents.Add
Sheets("Plan2").Select
Range("A" & i).Copy
.Selection.PasteAndFormat (wdFormatPlainText)
.Selection.TypeParagraph
Sheets("Teste").Select
Range(Cells((26 * (i - 1) + 1), 1).Address, Cells(((26 * (i - 1) + 7)), 3).Address).Copy
.Selection.PasteExcelTable True, False, False
.Visible = True
.Selection.TypeParagraph
Sheets("Teste").Select
Range(Cells((26 * (i - 1) + 8), 1).Address, Cells(((26 * (i - 1) + 16)), 3).Address).Copy
.Selection.PasteExcelTable True, False, False
.Visible = True
.Selection.TypeParagraph
Sheets("Teste").Select
Range(Cells((26 * (i - 1) + 17), 1).Address, Cells(((26 * (i - 1) + 25)), 3).Address).Copy
.Selection.PasteExcelTable True, False, False
.Visible = True
.Selection.TypeParagraph
End With
Next
End Sub
可以看到,这段代码一次交互粘贴了3张表,一共600张表!因此,一个一个地居中变得非常无聊。
非常感谢任何帮助!