我使用 Outlook 使用以下代码编辑主题和正文:
Sub SetupEmailTexts()
Dim olApp As Object
Dim olNameSpace As Object 'Outlook.NameSpace
Dim MailFolder As Object 'Outlook.MAPIFolder
Dim MyMail As Object 'Outlook.MailItem
GetSetup
Set olApp = CreateObject("Outlook.Application")
Set olNameSpace = olApp.GetNamespace("MAPI")
Set MailFolder = olNameSpace.GetDefaultFolder(16)
Set MyMail = MailFolder.Items.Add
MyMail.Display
MyMail.Subject = SubjectString
MyMail.HTMLBody = BodyString
MsgBox ("Edit subject and body before pressing OK")
If Not IsNull(MyMail) Then
PutSubjectBody MyMail.Subject, MyMail.HTMLBody
MyMail.Close olDiscard
End If
End Sub
如果在代码生成的消息框中按 OK 之前关闭 Outlook,我会在“PutSubjectBody MyMail.Subject,MyMail.HTMLBody”行中收到运行时错误“远程服务器计算机不存在或不可用”。如您所见,我尝试使用 IsNull 来确定 MyMail 是否仍然“活着”。我可以用什么来代替“IsNull”?