why this program doesn't work if Outlook is not manually launched?

Q

qwerty123456

Hello,
can someone tell me why this stupid program works if I run manually Outlook
2007, but doesn't work when Outlook2007 is not in execution?
The error is when accessing the Recipients collection. But I can't
understand why it works if Outlook 2007 is running previously I ran the
script.

Many thanks to all who will answer.

Luca D

' Copy the following text and put it into a new text file with the .vbs
extention
Dim oApp, oMail


Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.createitem(0)
oMail.subject = "Email Subject"
oMail.body = "hello all"
oMail.recipients.add("(e-mail address removed)")
oMail.send()
' uncomment the following to close Outlook
'oApp.quit()
 
Q

qwerty123456

The error is "Operation Aborted".

(I thought the program was so simple that worth a run)

Thanks
Luca D
 
D

Dmitry Streblechenko

Try the following:

Set oApp = CreateObject("Outlook.Application")
set oNS = oApp.GetNamespace("MAPI");
oNS.Logon;
Set oMail = oApp.createitem(0)
oMail.subject = "Email Subject"
oMail.body = "hello all"
oMail.recipients.add("(e-mail address removed)")
oMail.send()


--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
Q

qwerty123456

Excelent, now it works.

thanks
Luca D

Dmitry Streblechenko said:
Try the following:

Set oApp = CreateObject("Outlook.Application")
set oNS = oApp.GetNamespace("MAPI");
oNS.Logon;
Set oMail = oApp.createitem(0)
oMail.subject = "Email Subject"
oMail.body = "hello all"
oMail.recipients.add("(e-mail address removed)")
oMail.send()


--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 

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