我有以下内容来识别发件人电子邮件地址和名称(然后我将其存储以备后用):
strSender = itm.Sender.GetExchangeUser().PrimarySmtpAddress
strSenderName = itm.Sender
这很好用,但是当使用组电子邮件地址时(即多个用户可以发送电子邮件的地址,例如 customerservice@company.com),我收到如下错误消息:
运行时错误“91”:
对象变量或未设置块变量
知道如何解决这个问题吗?
完整脚本:
Public Sub saveAcct(itm As Outlook.MailItem)
Const Filepath1 = "C:\Users\tenba1\Documents\QlikView\Account Recons\Recon_Acct.txt"
Const Filepath2 = "C:\Users\tenba1\Documents\QlikView\Account Recons\Recon_Acct_Sender.txt"
Const Filepath3 = "C:\Users\tenba1\Documents\QlikView\Account Recons\Recon_Acct_SenderName.txt"
Const ForWriting = 2
strAccNumber = Trim(Mid(itm.Subject, InStrRev(itm.Subject, " "), Len(itm.Subject) - InStr(1, itm.Subject, " ")))
strSender = itm.Sender.GetExchangeUser().PrimarySmtpAddress
strSenderName = itm.Sender
Do Until FileExists("C:\Users\tenba1\Documents\QlikView\Account Recons\DONE.txt")
Loop
'Create a Busy file:
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("C:\Users\tenba1\Documents\QlikView\Account Recons\BUSY.txt", True)
MyFile.Close
'Delete the DONE file:
aFile = "C:\Users\tenba1\Documents\QlikView\Account Recons\DONE.txt"
Kill aFile
'Update the Account Number File:
Set objFSO1 = CreateObject("Scripting.FileSystemObject")
Set objFile1 = objFSO1.OpenTextFile(Filepath1, ForWriting)
objFile1.Write ("SET vAcct = '" & strAccNumber & "';")
'Update the Sender Email Address File:
Set objFSO2 = CreateObject("Scripting.FileSystemObject")
Set objFile2 = objFSO2.OpenTextFile(Filepath2, ForWriting)
objFile2.Write (strSender)
'Update the Sender Name File:
Set objFSO3 = CreateObject("Scripting.FileSystemObject")
Set objFile3 = objFSO3.OpenTextFile(Filepath3, ForWriting)
objFile3.Write (strSenderName)
'Launch the PowerShell Script for creating the recon file:
Dim shell
Set shell = CreateObject("wscript.shell")
shell.Run "C:\Users\tenba1\Documents\Scripts\Account_Recon.bat"
End Sub