Can't pass MailItem to a Sub

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
 
K

Ken Slovak - [MVP - Outlook]

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
 
W

Wolfram Humann

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top