Trying to start Outlook from VBA or VBS not working.

  • Thread starter Thread starter Trefor
  • Start date Start date
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.
 
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.
 
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.
 
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")
 
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.
 
Back
Top