Announcement

Collapse
No announcement yet.

Check if an Application is running

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Check if an Application is running



    Hi all, hope you can help me out here.

    From Excel, I'm writing another macro to send Lotus Notes emails, Add to Notes Doc libraries etc. However, I'm now attempting to automate the whole process. As a result, at the very start of the procedure, I want a function to run to test to see if the Lotus Notes Application is already open.

    I thought I would be able to use the
    Code:
    GetObject("","Notes.NotesSession")
    or
    Code:
    GetObject("","Notes.Application")
    However, these start the application if it is not already running. Is there a way around this?

    I've also tried to use the FindWindow API call however, depending where a user is within Lotus Notes, the application caption changes so this API call can't really be used.

    Any suggestions would be much appreciated.
    "Why write code when you can copy and paste someone elses?"

  • #2
    Re: Check if an Application is running

    Hi,

    I try to solve a similar problem. I have to check via Excel VBA if Outlook is running before another macro tries to send a mail. I found a workaround to test, wether Outlook is running or not (see code). The problem for me: if outlook is not running, I get an error message which I am not able to handle via "on error" (this is why I marked th "error" code as comment). If I solve the "error"....

    Maybe this could be a start...

    Urs



    Code:
    Sub test_if_outlook_is_running()
    
    'On Error GoTo errorhandler
    
      Dim appOL As Outlook.Application
      Dim a As String
      
      Set appOL = CreateObject("Outlook.Application")
    
      MsgBox (appOL.ActiveExplorer)
    
    'errorhandler:  MsgBox ("You have to start Outlook first")
    '  Exit Sub
    
    End Sub

    Comment


    • #3
      Re: Check if an Application is running

      I found some code that might help you out. Try this and see if it works for you.

      Place this code right after your declarations: (Don't forget to replace nSession with the name of the variable that you are using to for your Lotus Notes session.)

      Code:
      Dim sessionTest as String
      
      On Error GoTo errorHandler
      sessionTest = nSession.CommonUserName
      Next place this code at the end of the sub.

      Code:
      errorHandler:
      
      If Err = ERR_NOTES_SESSION_NOT_INIT Then
          MsgBox ("Lotus Notes Is Not Open")
      Else
          MsgBox ("Run Time Error " & Str(Err) & ":" & vbCrLf & Err.Description)
      End If
      If it can't be done in Excel, it doesn't need to be done at all.

      Comment


      • #4
        Re: Check if an Application is running

        Sorry.. but do you have a working sample..
        Thanks..

        Comment


        • #5


          Re: Check if an Application is running

          I am not sure where I got that code from and am currently using a different method to determine if Lotus Notes is running or not.

          Before I have my program try to send an email, I have it run this code first.

          Code:
          Sub checkIfNotesIsRunning()
          On Error GoTo notesIsNotRunning
              AppActivate ("Notes")
              Call sendEmail
          Exit Sub
          
          notesIsNotRunning:
          Dim notesErr, notesBox
          
              notesErr = "This program requires Lotus Notes to be running on your computer." & vbCrLf & vbCrLf
              notesErr = notesErr & "Please open Lotus Notes and try again."
                  notesBox = MsgBox(notesErr, vbCritical, "Lotus Notes Is Not Open")
              End
          End Sub
          If Lotus Notes is not running, it ends the program with a warning message.
          If it is running, it calles the sendEmail sub.

          I had to add this code to the beginning of the sendEmail sub to get the focus back on Excel.

          Code:
              AppActivate "Microsoft Excel"
                  Windows("emailGenerator.xls").Activate
                      Sheets("eGen").Select
          I have attached a working copy of my email VBA.
          Attached Files
          Last edited by storyM; March 17th, 2007, 04:17.
          If it can't be done in Excel, it doesn't need to be done at all.

          Comment

          Working...
          X