PDA

View Full Version : Run code if App running (W2K)



ja1clark
04-20-2004, 11:53 AM
Decided to repost since I still do not have answer.

All I am trying to do is run some code if Outlook is running - if it is not do nothing.

The following code works fine when Outlook is running but fails when Outlook is not running (Object required 'MyOutlook.ActiveExplorer'). Can anyone see the solution?


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

Set MyOutlook = CreateObject("Outlook.Application")
If TypeName(MyOutlook) <> "Nothing" Then
MyOutlook.ActiveExplorer.Activate

Wscript.Sleep 200
WshShell.SendKeys "%Vgc"
Wscript.Sleep 200
WshShell.SendKeys "%Fg"
WshShell.SendKeys "%S"
WshShell.SendKeys "%Y"
Set MyOutlook = Nothing
Else

Set MyOutlook = Nothing

End If
Wscript.Quit

Brf
04-20-2004, 12:09 PM
Replace the line:

If TypeName(MyOutlook) <> "Nothing" Then

with the line

If TypeName(MyOutlook.ActiveExplorer) <> "Nothing" Then

ja1clark
04-20-2004, 04:34 PM
This seems to work pretty good now except when Outlook is open on the desktop already it just flashes on the status bar. If it is minimized it works as expected.
If not running then nothing happens as expected.

Jama
04-20-2004, 07:40 PM
First of all, I'd like to apologise for the half answer I gave you in my last post. When participating in this forum, I do my best to provide as much help as I possibly can but my day job and other commitments makes it difficult at times.

I've looked thoroughly in Outlook's help file and managed to get to the Save as Web Page dialog box using the "reliable" Document Object Model but got stuck as I could not interact with that dialog from the script, so I had to look at the Sendkeys method and put together a few lines of code that will hopefully resolve your problem.

This is the DOM based script (does not work)

'================== Start =======================
Set MyOutlook = CreateObject("Outlook.Application")
Set myNameSpace = MyOutlook.GetNameSpace("MAPI")

Set MyOutlook.ActiveExplorer.CurrentFolder = _
myNameSpace.GetDefaultFolder(9)
MyOutlook.ActiveExplorer.Activate

MyOutlook.ActiveExplorer.CommandBars.Item("Menu Bar")_
.Controls("File").Controls("Save as Web Page...").Execute

Set MyOutlook = Nothing
Set myNameSpace = Nothing
'===================== eNd ======================


I will post the working script in the original thread and close this one in accordance with this forum's policy with regards to double posts.

If you need any further help, just let us know.

Yours


Jama