Can't pass MailItem to a Sub

  • Thread starter Thread starter Wolfram Humann
  • Start date Start date
W

Wolfram Humann

I hope I didn't strip down this test case too much...

I have a sub:
Sub ShowMailSubject(mail As MailItem)
MsgBox (mail.Subject)
End Sub

Somewhere else I have this code:
Dim myEmail As MailItem
ShowMailSubject (myOlApp.ActiveInspector.CurrentItem) ' Works
Set myEmail = myOlApp.ActiveInspector.CurrentItem
ShowMailSubject (myEmail) ' Fails

The first call to ShowMailSubject works and displays the subject as
expected. The second one fails with "Run-time error '424': Object
required".
Any Idea why?

Thanks,
Wolfram
 
Your code fails here on both calls.

Try calling the Sub like this:
Call ShowMailSubject(myEmail) ' Fails
Or
ShowMailSubject myEmail ' Fails

If that doesn't work then try fully qualifying your declaration of the
MailItem's:
Dim myEmail As Outlook.MailItem
 
Thanks a lot. That did it. Strange though that the first call works here
(Outlook 2000, Version: "9.0.0.6627"). That prevented my from suspecting
that something fundamentally was wrong with my Sub-Call syntax...

Wolfram
 
Back
Top