Jump to content
Macro Express Forums

"Error catch" problem


Recommended Posts

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?

Link to comment
Share on other sites

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.  

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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%

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

ScreenCapture_6_19_2024_13_25_06.jpg

Link to comment
Share on other sites

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"

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...