目前,我正在尝试创建一个子读取所选电子邮件的“发件人”字段,并仅将发件人的域设置为变量:
因此,如果我收到来自someone@example.com的电子邮件,我可以选择电子邮件,运行宏,它会将example.com(而非整个电子邮件)设置为我稍后可以使用的变量。
我感谢任何帮助!
答案 0 :(得分:0)
欢迎来到董事会。不知道为什么他们贬低你。但是这里是你怎么做的。
Option Explicit
Public savedDomain As String
Public Sub Example()
Dim mi As Outlook.MailItem
Dim emailAddress As String
If Not TypeName(Outlook.Application.ActiveWindow) = "Inspector" Then
Exit Sub
End If
Set mi = Application.ActiveWindow.CurrentItem
emailAddress = mi.SenderEmailAddress
'Save it a variable like you asked.
savedDomain = Mid(emailAddress, InStrRev(emailAddress, "@") + 1)
'But... State loss can do weird things, so I'd save it to registry
VBA.SaveSetting "MyExampleProgram", "SomeSectionName", "SavedDomain", savedDomain
'You get it back like so:
MsgBox VBA.GetSetting("MyExampleProgram", "SomeSectionName", "SavedDomain", vbNullString)
End Sub