Trying to start Outlook from VBA or VBS not working.

  • Thread starter Trefor
  • Start date Views 12,047
Status
Not open for further replies.
T

Trefor

I have the following code in a VBS, but Outlook is not starting. Am I missing

something?

Dim ObjOL

Set ObjOL= GetObject("Outlook.Application")

If Err <> 0 then

Err.Clear

Set ObjOL= CreateObject("Outlook.Application")

End If

I have also tried similar code from VBA and this does not work either and

there are no errors in VBA to give me a clue.

Trefor
 
K

Ken Slovak - [MVP - Outlook]

Do you have any On Error Resume Next statements in your code? I'm surprised

that you did not get some error message if you don't, usually something like

a 429 error (ActiveX cannot create object). Usually this is due to lack of

permissions or some script stopper running. Many A-V products such as Norton

or McAfee have script stoppers like that. If this is due to McAfee then you

can tell it to trust your code, go their support site to find out how. If

it's Norton then you're out of luck unless you disable the script stopper,

Norton doesn't care what you want to do.

"Trefor" <Trefor@home.com> wrote in message

news:D0051806-ACE2-4347-A130-23AF051053D6@microsoft.com...
> I have the following code in a VBS, but Outlook is not starting. Am I
> missing
> something?

> Dim ObjOL
> Set ObjOL= GetObject("Outlook.Application")
> If Err <> 0 then
> Err.Clear
> Set ObjOL= CreateObject("Outlook.Application")
> End If

> I have also tried similar code from VBA and this does not work either and
> there are no errors in VBA to give me a clue.

> > Trefor
 
T

Trefor

Ken,

Thanks for the reply. There is nothing wrong with the VBScript running

because other code is running fine.

I replaced: Set ObjOL= CreateObject("Outlook.Application")

with: WshShell.run "Outlook"

and of course:

Dim WshShell

Set WshShell=WScript.CreateObject("WScript.Shell")

and it works fine. Doesn't make sense to me, but it works so I'm happy ;)

Thanks.

Trefor
wrote:


> Do you have any On Error Resume Next statements in your code? I'm surprised
> that you did not get some error message if you don't, usually something like
> a 429 error (ActiveX cannot create object). Usually this is due to lack of
> permissions or some script stopper running. Many A-V products such as Norton
> or McAfee have script stoppers like that. If this is due to McAfee then you
> can tell it to trust your code, go their support site to find out how. If
> it's Norton then you're out of luck unless you disable the script stopper,
> Norton doesn't care what you want to do.

> >

>

> "Trefor" <Trefor@home.com> wrote in message
> news:D0051806-ACE2-4347-A130-23AF051053D6@microsoft.com...
> >I have the following code in a VBS, but Outlook is not starting. Am I
> >missing
> > something?
> > Dim ObjOL
> > Set ObjOL= GetObject("Outlook.Application")
> > If Err <> 0 then
> > Err.Clear
> > Set ObjOL= CreateObject("Outlook.Application")
> > End If
> > I have also tried similar code from VBA and this does not work either and
> > there are no errors in VBA to give me a clue.
> > > > Trefor


>
 
T

Trefor

Ken,

I found one of your posts re checking Send/Receive has completed using

Events. I seem to be having having the same issue using "synch.Start" as I

did using CreateObject to start Outlook i.e. it does nothing:

blnFinished = False

Set synch = olNS.SyncObjects.Item(1)

synch.Start

While blnFinished = False

DoEvents

Loop

This works fine for checking if it started ok though????

Set ObjOL= GetObject(, "Outlook.Application")

Trefor

"Trefor" wrote:


> Ken,

> Thanks for the reply. There is nothing wrong with the VBScript running
> because other code is running fine.

> I replaced: Set ObjOL= CreateObject("Outlook.Application")

> with: WshShell.run "Outlook"

> and of course:

> Dim WshShell
> Set WshShell=WScript.CreateObject("WScript.Shell")

> and it works fine. Doesn't make sense to me, but it works so I'm happy ;)

> Thanks.

> > Trefor

> " - " wrote:
>
> > Do you have any On Error Resume Next statements in your code? I'm surprised
> > that you did not get some error message if you don't, usually something like
> > a 429 error (ActiveX cannot create object). Usually this is due to lack of
> > permissions or some script stopper running. Many A-V products such as Norton
> > or McAfee have script stoppers like that. If this is due to McAfee then you
> > can tell it to trust your code, go their support site to find out how. If
> > it's Norton then you're out of luck unless you disable the script stopper,
> > Norton doesn't care what you want to do.
> > > >

> >

> > "Trefor" <Trefor@home.com> wrote in message
> > news:D0051806-ACE2-4347-A130-23AF051053D6@microsoft.com...
> > >I have the following code in a VBS, but Outlook is not starting. Am I
> > >missing
> > > something?
> > > > Dim ObjOL
> > > Set ObjOL= GetObject("Outlook.Application")
> > > If Err <> 0 then
> > > Err.Clear
> > > Set ObjOL= CreateObject("Outlook.Application")
> > > End If
> > > > I have also tried similar code from VBA and this does not work either and
> > > there are no errors in VBA to give me a clue.
> > > > > > > > Trefor

> >
 
K

Ken Slovak - [MVP - Outlook]

Does that synch.Start code have an event handler for the completion of the

synch that would set your blnFinished flag to True? If not that's a nice

endless loop you've set up.

The only reason I can think of for a failure for CreateObject() or New is

that there is some problem with the Outlook installation/registrations or

the aforementioned script stopper.

"Trefor" <Trefor@home.com> wrote in message

news:EF73F395-9789-48C4-A5D9-E2BFB9C3D0C5@microsoft.com...
> Ken,

> I found one of your posts re checking Send/Receive has completed using
> Events. I seem to be having having the same issue using "synch.Start" as I
> did using CreateObject to start Outlook i.e. it does nothing:

> blnFinished = False
> Set synch = olNS.SyncObjects.Item(1)
> synch.Start

> While blnFinished = False
> DoEvents
> Loop

> This works fine for checking if it started ok though????

> Set ObjOL= GetObject(, "Outlook.Application")

> > Trefor
 
Status
Not open for further replies.
Top