定期从 Excel 打印到 Adobe PDF,强制将 PDF 保存到正确路径的脚本
Regularly printing to Adobe PDF from Excel, script to force PDFs to be saved to correct path
我正在 Excel 处理一系列 XLS 文件。当我处理完它们后,我需要将它们打印成 PDF,以便将它们传送给我公司以外的一方。
我录制了一个相当基本的宏,以便每次都能使用相同的设置打印这些文件。不幸的是,它并没有做我需要它做的所有事情。
基本上,我希望 Adobe 在打印文件时询问我文件应该保存在哪里。我的脚本现在没有发生这种情况。如果我手动打印 select Excel 中打印机属性 window 的设置 "Ask to replace existing PDF file",它总是会询问我应该将文件保存在哪里。然而,我的脚本没有捕捉到这一点,我不确定我需要添加什么。
我有很多文件要处理(这是一项会重复出现的任务)所以越早确定越好。
这是我可以用 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:
Sub SaveAsPDF()
Dim SaveName as String
SaveName = InputBox("Save As File Name?")
ThisWorkbook.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=Application.ActiveWorkbook.Path & Application.PathSeparator & SaveName & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End Sub
我正在 Excel 处理一系列 XLS 文件。当我处理完它们后,我需要将它们打印成 PDF,以便将它们传送给我公司以外的一方。
我录制了一个相当基本的宏,以便每次都能使用相同的设置打印这些文件。不幸的是,它并没有做我需要它做的所有事情。
基本上,我希望 Adobe 在打印文件时询问我文件应该保存在哪里。我的脚本现在没有发生这种情况。如果我手动打印 select Excel 中打印机属性 window 的设置 "Ask to replace existing PDF file",它总是会询问我应该将文件保存在哪里。然而,我的脚本没有捕捉到这一点,我不确定我需要添加什么。
我有很多文件要处理(这是一项会重复出现的任务)所以越早确定越好。
这是我可以用 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:
Sub SaveAsPDF()
Dim SaveName as String
SaveName = InputBox("Save As File Name?")
ThisWorkbook.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=Application.ActiveWorkbook.Path & Application.PathSeparator & SaveName & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End Sub