1

我在下面编写了宏,以便使用中的工作表将打印为 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

如果有人可以帮助我修复此代码,那就太好了。

提前致谢。

4

2 回答 2

0

尝试这个:

SendKeys "^(a)" & "{DELETE}" & Filename & "{ENTER}", False

它删除打印对话框中的旧文件名

ps:在我的测试中,它仅在我将 waitTime 设置为 5 秒时才有效,但可能是我的机器速度较慢

于 2013-05-23T12:33:40.277 回答
0

查看Bullzip 示例

Set settings = CreateObject("Bullzip.PdfSettings")
settings.SetValue "Output", fileName
settings.WriteSettings True
于 2016-01-05T13:03:07.987 回答