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