将图表另存为PDF
我试图将我的工作表保存为使用vba的pdf文件。工作表比A4页宽,并包含几个形状(从一边到另一边)。我希望工作表能够放在一个A4页面上,所以它应该按照屏幕上看到的那样进行重新调整。我正在使用以下代码:将图表另存为PDF
Sub Print_PDF() Dim sFilename As String
Worksheets.Add.Name = "Helpsheet"
sFilename = "G:\anything\test.pdf"
ThisWorkbook.Worksheets("Newsletter").Range("A2:D81").CopyPicture xlScreen, xlBitmap
ThisWorkbook.Sheets("Helpsheet").Activate
ThisWorkbook.Sheets("Helpsheet").Paste
ActiveSheet.PageSetup.PrintArea = ThisWorkbook.Sheets("Helpsheet").Range("A1:O86")
With ActiveSheet.PageSetup
.Orientation = xlPortrait
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
ThisWorkbook.Sheets("Helpsheet").ExportAsFixedFormat Type:=xlTypePDF, Filename:=sFilename, quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
Application.DisplayAlerts = False
ThisWorkbook.Sheets("Helpsheet").Delete
Application.DisplayAlerts = True
End Sub
代码实际上会将PDF文件保存在预期位置。但是,PDF文件是4页而不是预期的1页。所以看起来这个打印区域没有正确定义。我究竟做错了什么?
回答:
您是否尝试过按照此示例调整PageSetup参数?
Application.PrintCommunication = False With ActiveSheet.PageSetup
.Orientation = xlLandscape
.Zoom = False
'.PrintArea = Worksheets(ReportWsName).UsedRange
.FitToPagesWide = 1
'.FitToPagesTall = 1
End With
Application.PrintCommunication = True
想一想明确地将.Zoom设置为false很重要。
来源: excel vba not exporting pagesetup to pdf correctly
回答:
假设活动页也是sheet("Helpsheet")
打印区域需要打印范围的地址。
ActiveSheet.PageSetup.PrintArea = ThisWorkbook.Sheets("Helpsheet").Range("A1:O86").Address
以上是 将图表另存为PDF 的全部内容, 来源链接: utcz.com/qa/263748.html