【发布时间】:2018-05-26 15:37:33
【问题描述】:
我有以下 VBA 代码,它基本上从 Excel 工作簿的工作表中获取图表并将它们粘贴到 PDF 文档中:
Sub Graphics()
Dim s As Workbook
Dim ws As Worksheet, wsTemp As Worksheet
Dim chrt As Shape
Dim tp As Long
Dim File As String
Dim NewFileName As String
Dim Path As String
Application.DisplayAlerts = False
Application.ScreenUpdating = False
'Here I define where the excel file is:
SourcePath = "\\ukfs1\users\gabriem\Documents\Misproyectos\BigPromotions\QAPromo"
'Name of excel file that contains the graphs:
File = "graphicator.xlsx"
'Open the excel file:
Set s = Workbooks.Open(SourcePath & "\" & File)
'Name of the PDF I will create with the excel graphs:
NewFileName = "\\ukfs1\users\gabriem\Documents\Mis proyectos\BigPromotions\QAPromo\test_pdf.pdf"
'Name of the excel sheet I want to export to PDF:
Set ws = s.Sheets("Negocios")
Set wsTemp = s.Sheets.Add
tp = 2
ts = 5
'Copy-Pasting process:
With wsTemp
For Each chrt In ws.Shapes
chrt.Copy
wsTemp.Range("A1").PasteSpecial
Selection.Top = tp
Selection.Left = ts
tp = tp + Selection.Height + 50
Next
End With
wsTemp.ExportAsFixedFormat Type:=xlTypePDF, Filename:=NewFileName, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
wsTemp.Delete
LetsContinue:
With Application
.ScreenUpdating = True
.DisplayAlerts = True
End With
Exit Sub
Whoa:
MsgBox Err.Description
Resume LetsContinue
End Sub
虽然代码运行良好,但它生成的输出在图形上不够充分,因为许多图形被剪切(其中一半在另一页中)。所以,我希望生成的 PDF 是水平的,但一直找不到答案。不是 Excel 的问题,而是 VBA 代码创建的新 PDF:
非常感谢!!
【问题讨论】:
-
您可以通过它的 PageSetup 控制大部分布局