OlFolder problem

A

amiga1200

When I use this code
Set myolApp = CreateObject("Outlook.Application")
Set myNameSpace = myolApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox).Items
I get the following error
Could not complete operation. One or more parameter values are not valid
But If I use a number instead of olFolderInbox everything is fine

Any ideas

Thanks
 
B

Brendan Reynolds

It looks like you are using late binding (no reference to the Outlook object
library), presumably so that your code will not be dependent on a specific
version of Outlook. As the constant olFolderInbox is defined in the Outlook
object library, VBA has no way of recognising it without that reference.
You'll need to either use the numeric value or, better, define your own
constants ...

Const myFolderInbox As Long = 6
....

Set MyFolder = myNameSpace.GetDefaultFolder(myFolderInbox).Items
 
A

amiga1200

How do I change late binding/

Brendan Reynolds said:
It looks like you are using late binding (no reference to the Outlook object
library), presumably so that your code will not be dependent on a specific
version of Outlook. As the constant olFolderInbox is defined in the Outlook
object library, VBA has no way of recognising it without that reference.
You'll need to either use the numeric value or, better, define your own
constants ...

Const myFolderInbox As Long = 6
....

Set MyFolder = myNameSpace.GetDefaultFolder(myFolderInbox).Items
 
B

Brendan Reynolds

In the VBA editor, choose References from the Tools menu, and select the
Microsoft Outlook 11.0 Object Library (or whatever version is present on
your PC).

Note that this does make your code dependent on that version of Outlook - if
you have a reference to the Outlook 11.0 object library (Outlook 2003) your
app will fail if you attempt to run it on a PC that has Outlook 2002 or
Outlook 2000 installed.

Of course, if the app is for your own use or if your organisation has
standardised on a specific version, that may not be a problem for you.
 

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