【发布时间】:2015-12-18 19:25:49
【问题描述】:
我需要构建一个规则脚本,将 Outlook 附件(特定于 Excel)保存到用户的硬盘上。然后我需要在这个excel附件中添加密码,然后转发。
使用 VBA Outlook 开发者工具(见下文)保存和转发电子邮件/附件非常简单。但是,我在向此附件添加密码时遇到了问题。这是可能的还是我需要一个外部脚本/程序来完成这项任务?此外,您还有其他建议吗?
Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
saveFolder = "c:\"
For Each objAtt In itm.Attachments
objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
Set objAtt = Nothing
Next
Call SendEmail
End Sub
Public Sub SendEmail()
Dim olApp As Outlook.Application
Dim olMail As Outlook.MailItem
Dim blRunning As Boolean
'get application
blRunning = True
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If olApp Is Nothing Then
Set olApp = New Outlook.Application
blRunning = False
End If
On Error GoTo 0
Set olMail = olApp.CreateItem(olMailItem)
With olMail
.Subject = "My email with attachment"
.Recipients.Add "jlanz@mmyemail.com"
.Attachments.Add "C:\test123.xlsx"
.Body = "Here is an email"
.Send
End With
If Not blRunning Then olApp.Quit
Set olApp = Nothing
Set olMail = Nothing
End Sub
【问题讨论】:
-
我怀疑你需要一个外部程序来解决这个问题。
-
添加对Excel库的引用然后打开文件,添加密码,保存,然后附加发送。