定期从Excel打印到Adobe PDF,脚本强制PDF文件保存到正确的path

我正在处理Excel中的一系列XLS文件。 当我完成这些工作之后,我需要将它们打印成PDF格式,以便将它们传输到我公司以外的一方。

我logging了一个相当基本的macros,允许我每次都用相同的设置打印这些文件。 不幸的是,这并不是我所需要做的一切。

基本上,我希望Adobe在打印文件时询问文件的保存位置。 这不是我的脚本现在正在发生。 如果我手动打印并从Excel的“打印机属性”窗口中select“询问replace现有PDF文件”的设置,它总是会询问我应该保存文件的位置。 我的脚本没有抓住这个,但是,我不知道我需要添加什么。

我有很多文件要通过(这是一个将会重演的任务),所以我越早得到这个更好的结果。

这是我可以用Excelmacros解决的问题,如果有的话,任何人都可以指向正确的方向吗?

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