我正在尝试创建一个 VBA 宏,根据电子邮件地址将电子邮件附件保存到文件夹中。例如,如果我从 joey@me.com 收到附件并通过电子邮件发送,我想将该附件保存到目录 \server\home\joey 或者如果我从 steve@me.com 收到附件,则附件应保存在 \server \家\史蒂夫。
最后,我想发送一封回复电子邮件,其中包含已保存文件的名称。我发现一些代码几乎可以满足我的要求,但我很难修改它。这一切都在 Outlook 2010 中完成。这就是我目前所拥有的。任何帮助将不胜感激
Const mypath = "\\server\Home\joe\"
Sub save_to_v()
Dim objItem As Outlook.MailItem
Dim strPrompt As String, strname As String
Dim sreplace As String, mychar As Variant, strdate As String
Set objItem = Outlook.ActiveExplorer.Selection.item(1)
If objItem.Class = olMail Then
If objItem.Subject <> vbNullString Then
strname = objItem.Subject
Else
strname = "No_Subject"
End If
strdate = objItem.ReceivedTime
sreplace = "_"
For Each mychar In Array("/", "\", ":", "?", Chr(34), "<", ">", "|")
strname = Replace(strname, mychar, sreplace)
strdate = Replace(strdate, mychar, sreplace)
Next mychar
strPrompt = "Are you sure you want to save the item?"
If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then
objItem.SaveAs mypath & strname & "--" & strdate & ".msg", olMSG
Else
MsgBox "You chose not to save."
End If
End If
End Sub