Type Mismatch when iterating through eMail-folder MailItems in Outlook 2003

S

schneider

Hi all,

In VBA, when trying this:

dim mi as Outlook.MailItem
set mi = Application.ActiveExplorer.Selection.Item(1) ' Here, Error 13
- Type mismatch occurs

I get a type mismatch error. If I declare mi as Object instead of
MailItem, the erroneous line works, but later when accessing
properties like mi.SenderName or functions like mi.SaveAs(), the
function crashes ("the function 'SaveAs' of object 'MailItem' failed.
Error Code: 8004010f"). When I examine the mi object, it says that it
is of type MailItem. mi.Class returns olMailItem (43), TypeName(mi)
returns "MailItem", etc.
Curiously, e.g. mi.Subject and mi.Class properties return correct
values, while mi.SenderName fails as mi.SaveAs() does.
Strangely, this does not happen for every Mail I select when running
the macro, and running the macro on another machine can but does not
always succeed.
The behaviour seems completely random. All machines are running
Windows XP SP2 with latest updates and Office 2003 SP2 accessing an
Exchange Server 2003.
Reading through this group there are some people who faced the same
problem, but since some properties work on the MailItem object, most
people didn't care about late binding and using the working
properties. In my case I have to use the SaveAs function which crashes
as described above.
Any hints/workarounds/cheats/whatever? Could it be an installation
issue? Reinstalling Office didn't help.
Thanks in advance.

Kind Regards,
Hannes
 
K

Ken Slovak - [MVP - Outlook]

So, let's play detective. If the code works on some mail items but not
others I'd doubt it's a problem that can be solved by
repair/reinstall/whatever, see if there are differences that you can find
with the items where the macro works and where it doesn't.

The other thing to check is why you're getting an error of MAPI_E_NOT_FOUND
for those items. Google on that error code and see if any of the reasons
that you're getting MAPI_E_NOT_FOUND apply to you.
 
S

schneider

So, let's play detective. If the code works on some mail items but not
others I'd doubt it's a problem that can be solved by
repair/reinstall/whatever, see if there are differences that you can find
with the items where the macro works and where it doesn't.

The other thing to check is why you're getting an error of MAPI_E_NOT_FOUND
for those items. Google on that error code and see if any of the reasons
that you're getting MAPI_E_NOT_FOUND apply to you.

Thanks for your reply. Since some MailItems work on one machine but
not one the other, I guess it could be an installation or
configuration issue - not necessarily with Office itself, but perhaps
with any other software? I'll try installing SP3 or using an older or
newer Outlook version (2002 or 2007), maybe it works then. I didn't
find anything on the web concerning my issue and the MAPI_E_NOT_FOUND
error that would bring any hints.
The messages that don't work show no difference to me from the ones
that work - I can use/modify them directly in Outlook with no
problems. Only in VBA they seem to differ. Strange behaviour.
Thanks in advance.

Regards,
Hannes
 
K

Ken Slovak - [MVP - Outlook]

If you have a MAPI viewer such as OutlookSpy (www.dimastr.com) it often
shows differences in properties that you don't see in the user interface.
I'd also suspect permissions issues possibly if the code works with the same
items on one setup and not the other. See that the permissions are for the
users represented by those Outlook logons.
 

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