【问题标题】:Outlook vba mailItem camelcaseOutlook vba mailItem驼峰式
【发布时间】: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


【解决方案1】:

TypeName 将显示活动对象的类型名称。如果它从未被初始化(null),你会看到“Nothing”

话虽如此,您究竟什么时候看到 dim 声明发生了变化?在 Outlook VBA 编辑器中?

【讨论】:

  • 我仍然不确定解决方案。我已经添加了上面的代码。请帮我看看!
  • VBA 不区分大小写,因此任何一个声明都可以。您从 TypeName 得到“Nothing”,因为该变量尚未初始化。这很好。您应该将“If TypeName(newMail) = TypeName(mail)”更改为“If TypeName(newMail) = “MailItem””
猜你喜欢
  • 2013-09-29
  • 2020-02-01
  • 2014-07-23
  • 2010-12-09
  • 2016-06-12
  • 2013-05-25
  • 2023-03-18
  • 2013-08-03
  • 2015-07-12
相关资源
最近更新 更多