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

  • Thread starter Thread starter qwerty123456
  • Start date Start date
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()
 
The error is "Operation Aborted".

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

Thanks
Luca D
 
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
-
 
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
-
 
Back
Top