Jump to content
Macro Express Forums

Window activate


Recommended Posts

This particular issue has plagued me for a very long time, and I just cannot figure out what the issue is.

 

I find that "Window Activate" is extremely unreliable. Whenever I develop scripts where, after one thing is done in one window another window must be activated before the macro proceeds, the macro simply hangs.

 

Today’s example. I wish to batch print to PDF all *.musx files in a given directory. For this to work, each *.musx files must first be opened, in turn. I have to:

1) Issue the open command to the first file in the list

2) Wait for the file to open

3) Issue a "print" command within the application (this will call Adobe Acrobat)

4) Wait for the PDF to have been compiled and open within Acrobat

5) Close the newly opened PDF

6) Reactivate the window of the original application

7) Close the file that was opened within that application

8) Continue on to the next file by looping back to step (1)

 

There are various dialog boxes that come up (Open, Print, Save PDF File As). In order for the "open" and "close" commands (sent as keystrokes) within the main application to function properly, the main application must be active. Hence my use of the Window Activate command.

 

I have experimented with "Exact Match," "Partial Match," "Partial Match" with "The name contains wildcards" checked and the use of the asterisk character. I have inserted delays in front and after the Window Activate commands. Sometimes it works, sometimes the macro hangs.

 

Is this a known problem? Again, I have had trouble with this for so long, it’s not even funny. But today, I just cannot get this process to work reliably. I have hundreds of PDFs to compile, and I don’t want to do this manually one file at a time.

 

MORE INFO

I just inserted an "If Window is Running" check. I placed the window title precisely; instead of typing it, I populated the field by selecting the window title via "Browse". The "If Window is Running" check is supposed to open a text box saying, the window is running. But that text box doesn’t even come up. In other words, the If function doesn’t see the window, even though it is visible.

Link to comment
Share on other sites

It's not what you want to hear, but over the years I too have found both Window Activate and Wait for Window Title unreliable. Some instances work, others don't.  I can often instead use Delay commands (determined by trial/error). Sometimes I've had to resort to other methods, such as pixel colour recognition, slowing down that section with Macro Playback Speed, etc.

 

This has been my experience over several versions of the OS, probably from 95 , 2000 and XP to Win 10. I assume some sort of timing conflict with the OS and/or other apps running simultaneously with the macro.

 

 

Link to comment
Share on other sites

Further to this... a brute force approach. It’s interesting that some "wait for window" calls in this script function 100% reliably; the one activating the main application, however, fails more often than not. I agree, it must be how this application manages window titles.

 

Be that as it may, I removed all calls for activating the main application window. Instead, as the macro is first called from within that application, with a scope set to that application, I use a left mouse click to click on the main application window, where needed. Now, the macro runs flawlessly. Saves a lot of tedious hassle...

Link to comment
Share on other sites

Echoing what terrypin said, I have never found Window Activate to be reliable.  I was about to suggest finding some totally different way of doing the activation, but I see you have already done exactly that.  Congratulations.  Must be an immense relief after all that frustration.🙂

Link to comment
Share on other sites

With reference to the original problem of printing multiple .PDF files.

 

You should be able to launch acrobat from the command line with parameters for the specific file, and to print to a specific printer.

 

This might reduce the amount of window manipulation that needs to be done by MEx?

 

https://stackoverflow.com/questions/619158/adobe-reader-command-line-reference

 

There is also a utility which may help you here - http://www.columbia.edu/~em36/pdftoprinter.html

 

I haven't looked at these options in any depth, but you may want to explore further.

 

 

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...
 Share

×
×
  • Create New...