我有一个excel工作表,我有一个宏将工作表作为PDF文件保存到我们网络上的目录中。当我在Excel中查看打印预览时,它在1张纸上。但是,当我打开PDF文件时,它正在流向第二页。它是横向格式化,在PDF中有一个1表和1个图表显示在第二张表的左侧(页面的右侧渗透到下一页)。
我已经尝试了很多东西来坚持下去,但它不会起作用。以下是我尝试过的一些事情:
任何见解都会很棒。 提前谢谢。
答案 0 :(得分:1)
我在导出一系列纸张(仅导出打印区域)时遇到了同样的问题,并且解决了。这是一个语法问题。 在ExportAsFixedFormat之前,不要放置“ Selection”,而要放置“ Activesheet” ,而将Activesheet放置为已导出的工作表之一。
ActiveWorkbook.Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
Sheets("Sheet1").Activate
Activesheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"D:\myPath\myFileName " & ".pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=showAfterSave
答案 1 :(得分:0)
...试
Sub Macro1()
ActiveWorkbook.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:="Example", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
From:=1, _
To:=1, _
OpenAfterPublish:=True
End Sub
答案 2 :(得分:0)
我知道这似乎很愚蠢,但我发现做两次解决问题:)
Sub Main(saveToPdf as boolean)
If saveToPdf Then
'save to pdf
ActiveSheet.Range(ActiveSheet.PageSetup.PrintArea).Select
Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"D:\myPath\myFileName " & year & ".pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Call oneMoreTimeBecauseItSolvesProblem(year, showAfterSave)
End If
End Sub
Sub oneMoreTimeBecauseItSolvesProblem(year As Integer, showAfterSave As Boolean)
On Error Resume Next
ActiveSheet.VPageBreaks(1).DragOff Direction:=xlToRight, RegionIndex:=1
Application.ScreenUpdating = True
'save to pdf
ActiveSheet.Range(ActiveSheet.PageSetup.PrintArea).Select
Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"D:\myPath\myFileName " & year & ".pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=showAfterSave
End Sub