我想使用VBA将一些Excel数据复制到word文档中
为打印区域A3构建excel数据。创建word文档后,我尝试将新word文档的纸张大小设置为A3。它给了我一个运行时错误
运行时错误' 5889' 请求的PaperSize在当前选定的打印机上不可用
我正在使用的VBA代码
Set obj = CreateObject("Word.Application")
obj.Visible = True
Set newobj = obj.Documents.Add
newobj.ActiveWindow.Selection.PageSetup.PaperSize = wdPaperA3
Sheets("Page1").Activate
Range("A1:Q18").Copy
newobj.ActiveWindow.Selection.PasteExcelTable False, False, True
newobj.ActiveWindow.Selection.InsertBreak Type:=7
尝试了一种不同的方法,也给了我同样的错误
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If wdApp Is Nothing Then
Set wdApp = GetObject("", "Word.Application")
End If
With wdApp
.Documents.Add
.Visible = True
End With
With wdApp.Selection
.PageSetup.Orientation = wdOrientPortrait
.PageSetup.PaperSize = wdPaperA3
.PageSetup.MirrorMargins = wdNarrow
.PasteSpecial , Link:=False, DataType:=14, _
DisplayAsIcon:=False
End With
Set wdApp = Nothing