Late binding issue with Outlook mail item from XL

X

XP

I'm trying to automate Outlook from XL to generate an email using LATE
BINDING. I have the following code so far, BUT it breaks when trying to
create a MailItem:

Dim oOL As Object
Dim oMAIL As Object
Set oOL = CreateObject("Outlook.Application")
Set oMAIL = oOL.CreateObject("Outlook.MailItem")

Can someone please correct my code so this will run correctly?

Thanks much in advance.
 
P

papou

Hi
Dim oOL As Object
Dim oMAIL As Object
Set oOL = CreateObject("Outlook.Application")
Set oMAIL = oOL.CreateItem(olMailItem)

HTH
Cordially
Pascal
 
X

XP

Thanks, but this method fails at the line:

Set oMAIL = oOL.CreateItem(olMailItem)

Any ideas?
 
D

Dave Peterson

Open up Outlook.
Go to its VBE
Show the immediate window
and type:
?olMailItem

You'll see a number returned. Use that number instead of olMailItem.

You'll want to do this for any other outlook constant that you use in your code.

(and you'll have 0 errors <vbg>.)
That was a hint.
 

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