将邮件项目打印为 pdf [英] Print mail item as pdf
问题描述
我正在尝试将 Outlook 文件夹中的所有邮件项目保存为 PDF.
I am attempting to save all of the mail items within a folder in Outlook as PDF.
Sub pdfConversion()
Dim outApp As Object, objOutlook As Object, objFolder As Object, myItems As Object, myItem As Object
Dim psName As String, pdfName As String
Set outApp = CreateObject("Outlook.Application")
Set objOutlook = outApp.GetNamespace("MAPI")
Set objFolder = objOutlook.GetDefaultFolder(olFolderInbox).Folders("PDF Conversion")
Set myItems = objFolder.Items
For Each myItem In myItems
myItem.PrintOut copies:=1, preview:=False, ActivePrinter:="Adobe PDF", printtofile:=True, _
collate:=True, prtofilename:="C:\Users\lturner\Documents\" & myItem.Subject & ".pdf"
Next myItem
End Sub
我使用的是 Outlook 2007,它没有将邮件保存为 PDF 的选项,因此我尝试使用 .PrintOut
方法.
I am using Outlook 2007, which doesn't have the option to save mails as PDF, hence I'm attempting to use the .PrintOut
method.
使用上述内容,我目前收到未找到命名参数"错误.我在互联网上的其他地方看过,但似乎找不到解决方案.
Using the above I am currently receiving a "Named argument not found" error. I've looked elsewhere on the internet, but cannot seem to find a solution.
推荐答案
我使用了 Krishna 和Eugene Astafiev 生成以下代码,该代码现在将从 myItem
生成 PDF 文档.
I used a combination of the answers posted by Krishna and Eugene Astafiev to produce the below code, which will now produce a PDF document out of the myItem
.
Dim objDoc As Object, objInspector As Object
For Each myItem In myItems
fileName = Replace(myItem.Subject, ":", "")
Set objInspector = myItem.GetInspector
Set objDoc = objInspector.WordEditor
objDoc.ExportAsFixedFormat folderPath & fileName & ".pdf", 17
Set objInspector = Nothing
Set objDoc = Nothing
Next myItem
发布此内容,以便将来偶然发现该问题的任何人都可以看到使用 WordEditor
属性的工作代码.
Posting this so anyone in the future who stumbles across the question can see the working code, which uses the WordEditor
property.
这篇关于将邮件项目打印为 pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!