在 Outlook 2013 中将发件人域保存为变量

Saving Sender's Domain as Variable in Outlook 2013

目前,我正在尝试创建一个子程序,它将读取 selected 电子邮件的 "from" 字段,并仅将发件人的域设置为变量:

因此,如果我收到来自某人@example.com 的电子邮件,我可以 select 电子邮件,运行 宏,它会设置 example.com(不是整个电子邮件)作为我以后可以使用的变量。

感谢任何帮助!

欢迎来到董事会。不知道他们为什么不赞成你。但这是按照您的要求进行操作的方法。

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