将 Excel 文件另存为 PDF 到特定路径
我想将 Excel 文件另存为 .pdf 文件到特定位置,然后通过邮件发送该文件。
我正在使用 Office 2000 :|
到目前为止,这是我的代码:
Application.ActivePrinter = "PDF995 on Ne00:"
ActiveSheet.PageSetup.PrintArea = Range("A68").Value
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
"PDF995 on Ne00:", Collate:=True
Set WB = ActiveWorkbook
Set oApp = CreateObject("Outlook.Application")
Set omail = oApp.Createitem(0)
With omail
.To = Range("B61").Value
.Subject = "Approved"
.Body
.Display
Rows("81:134").Select
Selection.EntireRow.Hidden = True
End With
我可以轻松保存文件并将其邮寄,但无法将其保存到特定位置。
我需要能够指定像“C:\path\file.pdf”这样的路径。
I would like to save an Excel file as a .pdf file to a specific location and then send the file in a mail.
I'm using Office 2000 :|
This is my code so far:
Application.ActivePrinter = "PDF995 on Ne00:"
ActiveSheet.PageSetup.PrintArea = Range("A68").Value
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
"PDF995 on Ne00:", Collate:=True
Set WB = ActiveWorkbook
Set oApp = CreateObject("Outlook.Application")
Set omail = oApp.Createitem(0)
With omail
.To = Range("B61").Value
.Subject = "Approved"
.Body
.Display
Rows("81:134").Select
Selection.EntireRow.Hidden = True
End With
I can easily save the file and mail it, but I can't save it to a specific location.
I need to be able to specificy a path like "C:\path\file.pdf".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您将文件保存到固定位置但无法选择位置,作为最后的手段,您始终可以使用 fso 的 MoveFile 将其移动到您指定的位置,
例如。如果文件始终保存为“C:\temp\file1.pdf”,并且您希望将其放在桌面上
如果您想检查现有文件冲突(我相信 fso 的 Move 不允许覆盖),请使用 CopyFile 与打开覆盖,然后根据需要删除源文件
如果您想使用文件对话框来选择目标,您可以使用 UserAccounts.CommonDialog 对象(尽管这不适用于 Vista)或 SAFRCFileDlg.FileOpen (几乎只能在 XP 上运行)或者借用 IE 提示框。 (不幸的是,据我所知,VBS 的选项并不是那么好)
在这里查看它们: http:// www.robvanderwoude.com/vbstech_ui_fileopen.php
If you have the file saved to fixed location but you're unable to choose where, as a last resort you could always use fso's MoveFile to move it to your specified location
eg. If the file is always saved as "C:\temp\file1.pdf", and you want it on desktop
If you want to check for an existing file conflict (I believe fso's Move doesn't allow for overwrite), use CopyFile with over-write switched on then Delete the source file if necessary
If you'd like to use a file dialog to choose the destination, you can use the UserAccounts.CommonDialog object (although that doesn't work with Vista) or SAFRCFileDlg.FileOpen (pretty much only works on XP) or borrow an IE prompted box. (Unfortunately the options aren't all that great with VBS to my knowledge)
Check them out here: http://www.robvanderwoude.com/vbstech_ui_fileopen.php
这有点复杂,因为您必须设置注册表项。
假设您拥有已安装初始注册表项的完整版 Adobe Acrobat:
首先,您具有注册表访问功能,并将其放入非工作表模块中:
然后,您使用以下代码来设置注册表项告诉 Adobe 在哪里保存文件。请注意,每次打印时都必须进行设置。
另请注意,“C:\Windows\splwow64.exe”是我的 Excel 2010 32 位所需的文件,对于您来说可能有所不同。要确定它(不会改变),首先手动打印为 PDF,然后转到注册表项并查看 HKCU\Software\Adobe\Acrobat Distiller\PrinterJobControl LastPDFPortFolder 项中使用的应用程序。然后使用该可执行文件的完整应用程序路径的名称。
It's a little complicated, as you have to set registry keys.
Assuming that you have a full version of Adobe Acrobat that has installed the initial registry keys:
First, you have the registry accessing functions, which you put in a non-sheet module:
Then, you use the following code to set the registry key that tells Adobe where to save the file. Note, it has to be set everytime you print.
Also Note, the "C:\Windows\splwow64.exe" is what I needed for my Excel 2010 32-bit, and it may be different for you. To determine it (which won't change) first print manually to PDF, then go to the registry key and see what application is used in the HKCU\Software\Adobe\Acrobat Distiller\PrinterJobControl LastPDFPortFolder key. Then use the name of the full application path for that executable.
试试这个:
Try this: