【发布时间】:2015-12-06 12:06:46
【问题描述】:
我正在尝试在 Outlook 2013 的 vba 中定义 MailItem 变量。但是,每次我键入 Dim mail AS MailItem 时,MailItem 都会更新为 mailItem 。据我了解,这不是正确的类型。当我尝试 MsgBox TypeName(mail) 时,它显示 Nothing。
我不知道为什么会这样。任何帮助将不胜感激。谢谢!
整个代码如下
Private Sub Items_ItemAdd(ByVal newMail As Object)
'On Error Resume Next
On Error GoTo ErrorHandler
Dim mail As Outlook.mailItem
If TypeName(newMail) = TypeName(mail) Then ***<-- I want this if block to execute. But it doesn't!***
Set mail = newMail
SaveAttachments (newMail)
End If
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub
【问题讨论】:
-
您知道 VBA 不区分大小写,不是吗?这意味着,“MailItem”和“mailItem”非常相似
-
是的。我知道。但是,为什么 TypeName 显示 Nothing 呢?
-
stackoverflow.com/help/mcve 跟进 Dimitry 的回答,您可能需要类似 Set mail = ActiveInspector.currentItem
标签: vba outlook camelcasing typename mailitem