cdavidson Posted June 3, 2015 Report Share Posted June 3, 2015 I have a macro to extract data from a program, convert the results from a pdf to excel file, then paste the information I'm interested in to another spreadsheet. Sometimes the pdf window won't activate, maybe after 20 repeats or so. I have a long enough delay, and activate window, and wait for window title which should be more than enough to bypass this issue but sometimes it just doesn't. After the macro waits for the pdf window title to appear after 10 minutes the macro aborts. Is there a way to put an IF command or use the macro in another macro so that if the macro aborts then it restarts itself? This would be helpful as sometimes I leave the macro running after I leave the office to go home and if it aborts there is no one around to restart it manually, losing hours that could have been used to extract the data. Thanks in advance! Quote Link to comment Share on other sites More sharing options...
Samrae Posted June 3, 2015 Report Share Posted June 3, 2015 Here are some things you could try. I have not tested any of these. 1. At the top of your macro add a command to write something somewhere, in the registry or in a file, that indicates the macro has started. At the end of the macro add a command to remove it. Have a second macro that runs on a schedule. Have it look for the indicator written by the first macro. If it is there then the macro will know that it started but did not finish. You can then have the second macro rerun the first. 2. Similar to #1, use the "Log Data to File" or "Log Errors to File" command to indicate when the macro started and have a second macro look to see if it finished. 3. Use the "Log Errors to File" command and select the "Do not display error messages (log only)" option. This will make entries in the log file that the macro started, that it had an error, and it didn't finish. Your macro could look at the log file to restart the macro or handle the error as needed. Note that Macro Express Pro has an "On Error" handler for each macro command. That allows macros to handle error conditions and recover. Quote Link to comment Share on other sites More sharing options...
acantor Posted June 4, 2015 Report Share Posted June 4, 2015 I would make two copies of the macro. Name one "ABCD 1" and the other "ABCD 2". Use the "On Error" handler to launch the cloned version, and then stop. In other words, "ABCD 1" calls "ABCD 2"; and vice versa. I am not sure if Version 3 supports error handlng, but Version 4 definitely does. Quote Link to comment Share on other sites More sharing options...
Richard_4641 Posted June 21, 2015 Report Share Posted June 21, 2015 A little late, but if you're still interested... This should do it, "Your PDF Window" is of course the (possibly partial) window title of the program your using. Depending on your computer, you might want to put some delays in there. Don't use "Wait for Window Title" and delays probably won't be necessary, the loop should catch the window title as soon as it's on top. If it still sticks, You could try... And as a last resort... 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.