none
How Find Out If Outlook Is Loaded? RRS feed

  • Question

  • Hello. I have programmed Outlook from Visual FoxPro to send e-mails to my client's customers, but Outlook must be open for my code to work. When the users forget this, they encounter error messages that are a little difficult to recover from since parts of the overall process this belongs to have already occurred. Is there a simple way I can find out whether Outlook is already open (has been loaded? is that same thing?) at the moment that  users start the process? Thanks.


    Peyton

    Monday, October 28, 2013 3:31 PM

Answers

All replies

  • I don't think you can check from VBA if outlook.exe is running, but what are the issues with your code when Outlook is not running? Are you calling Namespace.Logon?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, October 28, 2013 5:43 PM
  • To be honest, the errors are not THAT difficult to recover from - I'd just have to un-do the changes made by the process up to the point where it starts e-mailing, but I'd have to write the code to do that, and I'd also have to learn how to do error trapping in VFP, which I've never done - and perhaps also learn to trap an error reported by Outlook (or by OLE - see below).  Believe it or not, this is occurring in a system I wrote in FoxPro for DOS 1,000 years ago, which I've now managed to get running in VFP after some effort - but it's still 99% old FoxPro 2.5 (i.e. DOS) code. For some new changes the client wanted, I had to learn how to program Outlook remotely from VFP, which I've never written in before this, so I'm a novice. So it would save me a lot of trouble if there's a way to check up front if Outlook is running  and abort the process with a reminder to the user before that.

    As to Namespace.Logon, what's that? The client's Outlook does require a password if that matters.

    The error message is "OLE error code 0x80004004. Operation aborted.", and occurs on the loNewMail.Send statement, which is odd since that's after everything has allegedly been prepared without any error message, using CREATEOBJECT('Outllook.Application') and setting the To, Subject, and HTMLbody of the loNewMail object, etc. - all of it being done using code that runs fine and sends e-mails with no problem as long as Outlook is manually loaded beforehand...

    Anyway, what's the difference between what happens with CREATEOBJECT and simply loading it? No doubt it has partly to do with whether VFP knows of its existence. Come to think of it, though, I'm also programming Word remotely via VFP, and that works even if Word has not be manually loaded beforehand...

    I don't think it's a password issue since the code runs on my own PC with Outlook manually loaded, and my Outlook does not require a password.


    Peyton



    • Edited by Petun Tahd Wednesday, October 30, 2013 2:58 AM
    Wednesday, October 30, 2013 2:49 AM
  • GetObject() would tell you if Outlook was running or not instead of CreateObject().

    Ken Slovak MVP - Outlook

    Wednesday, October 30, 2013 2:55 PM
    Moderator