【发布时间】:2015-05-08 14:32:19
【问题描述】:
我正在 Excel 中处理一系列 XLS 文件。完成后,我需要将它们打印为 PDF,以便将它们传输给我公司以外的一方。
我录制了一个相当基本的宏,让我每次都可以使用相同的设置打印这些文件。不幸的是,它并没有做我需要做的一切。
基本上,我希望 Adobe 在打印文件时询问我应该将文件保存在哪里。我的脚本现在没有发生这种情况。如果我手动打印并从 Excel 的“打印机属性”窗口中选择“要求替换现有 PDF 文件”设置,它总是会询问我应该将文件保存在哪里。但是,我的脚本没有捕捉到这一点,我不确定我需要添加什么。
我有很多文件要处理(这是一项会重复执行的任务),所以我越早确定越好。
这是我可以使用 Excel 宏解决的问题吗?如果可以,谁能指出我正确的方向?
Sub PrintToAdobeRedactions()
'
' PrintToAdobeRedactions Macro
' Print redacted worksheets to Adobe with correct settings every time.
'
' Keyboard Shortcut: Ctrl+e
'
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
Application.PrintCommunication = True
ActiveSheet.PageSetup.PrintArea = ""
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = "[Tab]"
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = "Page [Page]"
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.75)
.RightMargin = Application.InchesToPoints(0.75)
.TopMargin = Application.InchesToPoints(1)
.BottomMargin = Application.InchesToPoints(1)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintSheetEnd
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlOverThenDown
.BlackAndWhite = False
.Zoom = 100
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = False
.EvenPage.LeftHeader.Text = ""
.EvenPage.CenterHeader.Text = ""
.EvenPage.RightHeader.Text = ""
.EvenPage.LeftFooter.Text = ""
.EvenPage.CenterFooter.Text = ""
.EvenPage.RightFooter.Text = ""
.FirstPage.LeftHeader.Text = ""
.FirstPage.CenterHeader.Text = ""
.FirstPage.RightHeader.Text = ""
.FirstPage.LeftFooter.Text = ""
.FirstPage.CenterFooter.Text = ""
.FirstPage.RightFooter.Text = ""
End With
Application.PrintCommunication = True
ActiveWorkbook.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
End Sub
【问题讨论】:
-
为什么不直接使用另存为 PDF?为什么要打印为 PDF?
-
@Chrismas007 -1st line 读取 .xls 文件,OP 是否有 xl'07 或更新版本