0
votes

I am trying to define a MailItem variable in vba in Outlook 2013. However, every time I type Dim mail AS MailItem the MailItem gets updated to mailItem. As I understand, this is not a correct type. When I try MsgBox TypeName(mail), it shows Nothing.

I have no clue why this is happening. Any help will be really appreciated. Thanks!

The entire code is as follows

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
1
You know that VBA is NOT case-sensitive, don't you? That means, the "MailItem" and "mailItem" are pretty the sameLeo Chapiro
yes. I do know that. However, why is the TypeName displaying Nothing then?aakashgupta.0205
stackoverflow.com/help/mcve Following up on Dimitry's answer you likely need something like Set mail = ActiveInspector.currentItemniton

1 Answers

0
votes

TypeName will display the type name of a live object. If it's never been initialized (null), you will see "Nothing"

That being said, when exactly do you see the dim statement changed? In the Outlook VBA editor?