我写了一个小的宏,它需要每日Excel报告并将其打印到特定的打印机(打印到PDF)。当我运行宏时,我仍然错过了最后的步骤。按原样运行它,我仍然需要点击弹出的“保存”按钮,并且必须导航到正确的文件路径。有没有办法让它自动为我保存按钮,并将文件保存到正确的文件夹中(如下面的代码所示)?以正确的文件路径和正确的文件名打印到PDF
Sub printToPDF()
'declare variable for my file path
Dim filePath As String
'declare variable for my file name
Dim fileName As String
fileName = "Operations_Daily_Outage_Report_" & Format(Date, "yyyy-mm-dd")
filePath = "M:\Daily_Outage_Report\Active"
Worksheets("general_report").PageSetup.CenterVertically = False
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:="Foxit Reader PDF Printer"
End Sub
这是一个足够老的Excel版本,你不能保存为.pdf?或者是否有其他一些原因是通过PDF驱动程序打印的? – Comintern
您有三种选择:https://support.office.com/zh-cn/article/Save-as-PDF-d85416c5-7d77-4fd6-a216-6f4bf7c7c110或https://msdn.microsoft.com/zh-cn/ us/library/windows/desktop/ms644950(v = vs.85).aspx或https://msdn.microsoft.com/en-us/library/office/ff821075.aspx – cyboashu
如果我简单地保存为PDF,可以我仍然将它设置在'PageSetup.CenterVertically = False'的地方?其中一部分是我的学习练习。 – Rivers31334