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

Status
Not open for further replies.
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("youremail@yourprovider.com")

oMail.send()

' uncomment the following to close Outlook

'oApp.quit()
 
S

Sue Mosher [MVP]

It's hard to answer your question without knowing what the error is. I'd

suggest you take a look at the code sample at

http://www.outlookcode.com/codedetail.aspx?id=83, paying particular

attention to the Logon statement.

Sue Mosher

"qwerty123456" <qwerty123456> wrote in message

news:115C4E02-DF36-4B0D-B388-CF630711DA05@microsoft.com...
> 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("youremail@yourprovider.com")
> oMail.send()
> ' uncomment the following to close Outlook
> 'oApp.quit()

>
 
Q

qwerty123456

Re: why this program doesn't work if Outlook is not manually launc

The error is "Operation Aborted".

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

Thanks

Luca D

"Sue Mosher [MVP]" wrote:


> It's hard to answer your question without knowing what the error is. I'd
> suggest you take a look at the code sample at
> http://www.outlookcode.com/codedetail.aspx?id=83, paying particular
> attention to the Logon statement.

> > Sue Mosher
> > >

> "qwerty123456" <qwerty123456> wrote in message
> news:115C4E02-DF36-4B0D-B388-CF630711DA05@microsoft.com...
> > 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("youremail@yourprovider.com")
> > oMail.send()
> > ' uncomment the following to close Outlook
> > 'oApp.quit()
> >


>
 
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("youremail@yourprovider.com")

oMail.send()

Dmitry Streblechenko (MVP)

-

"qwerty123456" <qwerty123456> wrote in message

news:115C4E02-DF36-4B0D-B388-CF630711DA05@microsoft.com...
> 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("youremail@yourprovider.com")
> oMail.send()
> ' uncomment the following to close Outlook
> 'oApp.quit()

>
 
Q

qwerty123456

Re: why this program doesn't work if Outlook is not manually launc

Excelent, now it works.

thanks

Luca D

"Dmitry Streblechenko" wrote:


> 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("youremail@yourprovider.com")
> oMail.send()

> > Dmitry Streblechenko (MVP)
>

>

>

> -
> "qwerty123456" <qwerty123456> wrote in message
> news:115C4E02-DF36-4B0D-B388-CF630711DA05@microsoft.com...
> > 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("youremail@yourprovider.com")
> > oMail.send()
> > ' uncomment the following to close Outlook
> > 'oApp.quit()
> >


>
 
Status
Not open for further replies.
Top