【发布时间】:2017-11-22 19:29:17
【问题描述】:
我有一个 Excel 文件,其中有一个“生成 PDF”按钮,该按钮运行一个宏以将某个工作表(我们称之为“QUOTE”)打印到 PDF 中。这张表的边距非常有限,在我的电脑中,创建的 PDF 具有完美的结构:所有内容都很好地包含在 1 页中。但是,在其他一些计算机中,当创建 PDF 时,所有内容都不适合 1 页,并且会创建带有一些内容的第 2 页。这是代码(包括通过限制边距来解决此问题的尝试):
Sub Excel_Export_Proposal()
Dim wb As Workbook: Set wb = ThisWorkbook
Dim wsCOTIZACION As Worksheet
Dim Proposalname As String
Dim iVis As XlSheetVisibility
Dim xlName As Excel.Name
Dim FolderPath As String
Dim myRange As String
Set wsQUOTE = ThisWorkbook.Sheets("QUOTE")
FolderPath = ActiveWorkbook.Path & "\"
Proposalname = "Quote for " & CStr(Range("B2").Value)
wsQUOTE.PageSetup.PrintArea = myRange
With wsQUOTE.PageSetup
.FitToPagesTall = 1
.FitToPagesWide = False
.Zoom = False
.LeftMargin = Application.InchesToPoints(0.7)
.RightMargin = Application.InchesToPoints(0.4)
.BottomMargin = Application.InchesToPoints(0.75)
.TopMargin = Application.InchesToPoints(0.75)
End With
'Proposal
Application.ScreenUpdating = False
wb.Unprotect
With wsQUOTE
iVis = .Visible
.Visible = xlSheetVisible
.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=ActiveWorkbook.Path & "\" & Proposalname & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=True, _
OpenAfterPublish:=True
.Visible = iVis
wsQUOTE.Activate
End With
wb.Protect
Application.ScreenUpdating = True
End Sub
有人可以帮我解决这个问题吗?我希望无论生成何种计算机或软件,我们都能完美打印该表...
【问题讨论】:
-
工作表的页面设置是否已设置为“适合 1 页宽 x 1 高”?抱歉,我只向下滚动到您正在打印的位置 - 我没有看到您在打印后将其更改为那个位置。为什么不将其设置为 1 页高在打印之前?
-
是的,Tall=1 和 Wide=False,就像代码中显示的那样
-
尝试在打印到 PDF 文件之前这样做。
-
我试试,谢谢!
-
您的意思是选择范围内包含的单元格?不是用 wsQUOTE.PageSetup.PrintArea = myRange 命令完成的吗?