我在下面编写了宏,以便使用中的工作表将打印为 PDF,并根据特定单元格的内容填充文件名。
它几乎可以工作,但由于某种原因,每当我运行它时,它都会声明“输出文件夹不存在”。这是因为由于某种原因文件路径加倍
(即S:\Purchase Orders\2013\TEST - Damien\2013 Pos\S:\Purchase Orders\2013\TEST - Damien\2013 POs\filename.pdf
Sub SaveToPDF()
' This line of code calls your PDF printer and runs the conversion. Record your own macro to call your PDF printer and copy and paste it here.
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
"Bullzip PDF Printer", Collate:=True
' This set of code tells the macro to pause for 2 seconds. This will allow for the PDF printer to run through its process and prompt you for a filename.
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 2
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
' This line of code specifies your directory as well as the cell or range which you want the filename to come from.
FileName = "S:\Purchase Orders\2013\TEST - Damien\2013 POs\" & ActiveSheet.Range("BT12").Value
' This line of code sends the filename characters and the ENTER key to the active application (i.e. the prompt window). The "False" statement allows the macro to continue running without waiting for the keys to be processed.
SendKeys FileName & "{ENTER}", False
End Sub
如果有人可以帮助我修复此代码,那就太好了。
提前致谢。