acantor Posted June 17 Report Share Posted June 17 I've written a Macro Express script that switches from the focused window, which happens to be a Word document, to an open Outlook message. If an Outlook email message cannot be found, the script signals an error. I've set the "Window Activate" instruction to handle the error. Then I use "On Error" and "Catch Error" to deal with the situation: Window Activate: - Message // Switch to a window that has " - Message" in the titlebar On Error Catch Error: Window could not be found MessageBox: An Outlook message must be open Macro Stop End Catch Error End Error The problem: If no Outlook messages are open, the script doesn't catch the error. Is there something I'm overlooking? Or have I stumbled on a bug? Quote Link to comment Share on other sites More sharing options...
acantor Posted June 17 Author Report Share Posted June 17 I think it's a bug. The "Window could not be found" error is acting like the "Program could not be launched" error. I'll report the issue to Insight. Quote Link to comment Share on other sites More sharing options...
rberq Posted June 17 Report Share Posted June 17 I was just about to test your problem. But I will wait now since you have contacted Insight. I recall a problem recently with "if Not Window ..." but rather than follow it up I took the lazy way out -- inverted the logic to say "If Window ..." and then the macro did what I wanted. Quote Link to comment Share on other sites More sharing options...
acantor Posted June 18 Author Report Share Posted June 18 Six months or a year ago, the same thing happened to me. I couldn't get a macro to work with an "If Not..." statement, but I was able to get it to run when I inverted the logic. Like you, I took the path of least resistance! The macro I'm writing is for a client, so error trapping is kinda needed. Quote Link to comment Share on other sites More sharing options...
acantor Posted June 18 Author Report Share Posted June 18 Maybe error trapping isn't needed. I want the macro to stop if two conditions are not met: 1. Stop if Outlook isn't running, or 2. Stop if Outlook is running but a message (or a meeting) is not open. Windows for messages and meetings contain the identical title bar text: " - Me" For example: Hello - Message (HTML) Goodbye - Meeting This seems to be working. (I tried using Windows controls for the Outlook message, but no luck!) // While Word is focused, send the Outlook hotkey to open the NEXT email message. // Then switch back to Word. // Get handle of current Word document... Variable Set Handle %WordHandle% from a window with the title, " - Word" // Make sure Outlook is running... If Not Program "OUTLOOK.EXE" is running MessageBox: Next message in Outlook Macro Stop End If // Make sure an Outlook message or meeting is open... If Not Window " - Me" is running MessageBox: Next message in Outlook Macro Stop End If // Switch to an open Outlook email ME_ssage or ME_eting... Window Activate: - Me Delay: 50 milliseconds // Slight delay may be needed // Send the Outlook hotkey to open the next message (or meeting)... Text Type (Simulate Keystrokes): <CONTROL>. Delay: 250 milliseconds // Slight delay is needed // Switch back to Word... Window Activate: %WordHandle% Quote Link to comment Share on other sites More sharing options...
acantor Posted June 19 Author Report Share Posted June 19 I reported the issue to Insight, and they investigated. The source of the problem is not with Macro Express, but with Outlook. Closing an Outlook message doesn't actually close the window. Instead, the window turns invisible, or rather, it becomes dimensionless. Its top, left, width, and height values are 0. My effort to trap an error failed because Macro Express "sees" these invisible windows. I'm using Outlook 2019. Not sure whether other versions of Outlook "invisible-ize" message windows. Quote Link to comment Share on other sites More sharing options...
rberq Posted June 19 Report Share Posted June 19 Interesting! I have a macro that is activated by the Firefox window, then loops forever until Firefox goes away: Variable Set String %repeater% to "0" Repeat Until %repeater% Equals "1" // Repeat forever Delay: 1 seconds, without ability to halt If Window "Mozilla Firefox" is focused // End macro if Firefox loses focus Else Macro Return End If etc. etc. etc. But sometimes it keeps right on running after I have ended Firefox. That's not a big deal, so I haven't bothered about it. But I will try looking at the window dimensions as a second way to end it. Incidentally, I think this is the macro I mentioned above where "If Not Window ..." caused problems. See screen shot below. Is ME smart enough to recognize the double negative? Quote Link to comment Share on other sites More sharing options...
acantor Posted June 20 Author Report Share Posted June 20 I find Macro Express handles "double negatives" like in your example better than the software running between my two ears! It's hard to keep these straight. If the script sometimes fails, perhaps it's due to the "Window Title" match. If your macro happens to include the word "Firefox" in its nickname, and if you are in the process of editing that macro, the script will act on the Script Editor window. It might produce less ambiguity to specify "Mozilla Firefox", perhaps adding the dash that appears in the Firefox title bar: " — Mozilla Firefox" Quote Link to comment Share on other sites More sharing options...
rberq Posted June 20 Report Share Posted June 20 7 hours ago, acantor said: the software running between my two ears As my father used to remind me: "Use your head for something besides keeping your ears apart." 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.