Hello,
Is there a way to tell if Outlook is open in the notification area (automate mode with wheel icon), or if there's an Outlook window already open?
Thank you.
Hello,
Is there a way to tell if Outlook is open in the notification area (automate mode with wheel icon), or if there's an Outlook window already open?
Thank you.
Option Explicit Sub TestOutlookIsOpen() Dim oOutlook As Object On Error Resume Next Set oOutlook = GetObject(, "Outlook.Application") On Error GoTo 0 If oOutlook Is Nothing Then MsgBox "Outlook is not open, open Outlook and try again" Else MsgBox "Outlook is open." End If End Sub
Hi Logit. Thanks for the reply, but I do have similar code already. My problem is that this method only tells me if the application is running, but not if the Outlook window is open.
I have a macro that opens an instance of Outlook (hidden in the system tray, in automation mode), runs some code and at one point it calls an inspector, which requires a window to be open, otherwise it fails.
So, I open one with .Display, but if there's a window already visible, it opens a second one, and I'm trying to prevent that by detecting if Outlook is on the system tray or if there's a window active.
I hope I explained myself clearly.
Is there a built-in method for that in VBA?
What I am finding on the internet is not working as stated in their posting.
What about checking to see if Outlook is running ... if not, start it. Obviously, Outlook would be 'open' at that point.
If it is already running, you could stop that process, then re-open it ?
You could check the activewindow.class e.g.
The full list of results is at https://docs.microsoft.com/en-us/off....OlObjectClassDim lClass As Long lClass = Outlook.Application.ActiveWindow.Class If lClass = 34 Then 'The activewindow is an Explorer object
Graham Mayor - MS MVP (Word) 2002-2019
Visit my web site for more programming tips and ready made processes
http://www.gmayor.com
gmayor :
I looked at a similar macro (as yours) but if you are running the macro from a separate workbook, then the "activewindow" would be that excel workbook and not Outlook.
How would you get vba to recogize Outlook as the active window ?
If you are working from Excel and Outlook is open, then
If Outlook is not open then you would have to open it and select the required item in Outlook, which would make this code superfluous. In fact it is undoubtedly better to select what you wish to process in either instance.Dim olApp As Object Dim lClass As Long Set olApp = GetObject(, "Outlook.Application") lClass = olApp.ActiveWindow.Class If lClass = 34 Then 'The Outlook active window is an Explorer object
In that case look to ensure that Outlook is correctly opened from Excel - see http://www.rondebruin.nl/win/s1/outlook/openclose.htm
Graham Mayor - MS MVP (Word) 2002-2019
Visit my web site for more programming tips and ready made processes
http://www.gmayor.com
Hi gmayor,
That ObjectClass method works very well. Do you know if I can do something similar with Word? Was not able to find an equivalent property.
Excel or Word, the coding to process Outlook would be similar.
Graham Mayor - MS MVP (Word) 2002-2019
Visit my web site for more programming tips and ready made processes
http://www.gmayor.com
I meant if I want to test an open Word application window, instead of Outlook. I looked at the Word Object references but seem to be very different.
OK. Simply set a variable to open the named document. Word, unlike Excel, simply switches to that document if it is already open.
Dim oDoc As Document Set oDoc = Documents.Open(FileName:="C:\Path\filename.docx", AddtoRecentFiles:=False) 'do something with oDoc
Graham Mayor - MS MVP (Word) 2002-2019
Visit my web site for more programming tips and ready made processes
http://www.gmayor.com
I see. Thanks for your help gmayor and Logit!
You are welcome.
Aljhone
What does your provided link have to do with the OP question ?
@logit. aljhone has hit the showers, having been benched from the game.
Remember To Do the Following....
Use [Code].... [/Code] tags when posting code to the thread.
Mark your thread as Solved if satisfied by using the Thread Tools options.
If posting the same issue to another forum please show the link