|
以下代码实现将未读邮件(包括附件)保存到C:\,然后打印附件。我想你应该可以用得上。
Private Declare Function ShellExecute Lib "shell32.dll" _ Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _ ByVal lpFile As String, ByVal lpParameters As String, _ ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Sub SaveandPrint() Dim olApp As New Outlook.Application Dim nmsName As Outlook.NameSpace Dim fldFolder As Outlook.Folder Dim vItem As Object Set nmsName = olApp.GetNamespace("MAPI") Set fldFolder = nmsName.GetDefaultFolder(olFolderInbox) If fldFolder.UnReadItemCount > 0 Then For Each vItem In fldFolder.Items If vItem.UnRead = True Then strname = vItem.Subject strname = Replace(strname, "*", "_") strname = Replace(strname, "\", "_") strname = Replace(strname, "/", "_") strname = Replace(strname, "$", "_") strname = Replace(strname, "%", "_") strname = Replace(strname, "!", "_") strname = Replace(strname, "~", "_") strname = Replace(strname, "(", "_") strname = Replace(strname, ")", "_") strname = Replace(strname, "+", "_") strname = Replace(strname, ":", "_") vItem.SaveAs "C:\" & strname & ".txt", olTXT '-----保存附件------- For Each att In vItem.Attachments att.SaveAsFile "C:\" & att.FileName '使用shell print打印文档 strFile = "C:\" & att.DisplayName ' 下一个文档 ReturnVal = ShellExecute(0&, "print", strFile, 0&, 0&, 0&) Next '------保存附件-------- vItem.UnRead = False End If Next End If Set fldFolder = Nothing Set nmsName = Nothing End Sub
|
|