Jump to content
Macro Express Forums

Handling the 'Confirm Replace' window?


Recommended Posts

This is pretty elementary I know, but my brain's not working in full gear ...

 

The fragment below is from a macro which is copying a file from folder A, opening folder B and pasting it in. But sometimes the file exists already so the standard confirmation question appears, asking for a Yes (default) or No (my choice). Is my code below the usual way to handle this please?

 

Clipboard Paste // Paste the file copied from folder A.
Delay: 100 milliseconds
If Window "Confirm File Replace" is focused
 Text Type (Simulate Keystrokes): n // Type N for No.
 Delay: 100 milliseconds
Else
Text Type (Simulate Keystrokes): y // Type Y for Yes
 Delay: 100 milliseconds
End If
Text Type (Simulate Keystrokes): <ALT><F4> // Close folder B.
Delay: 100 milliseconds


Link to comment
Share on other sites

I'd do it rather differently!

Clipboard Paste
Wait for Window Title: Confirm File Replace -- wait 1 second
On Error
 Catch Error: The condition was not met within the specified amount of time -- i.e. the file did not already exist
Goto:CopyDone
 End Catch Error
End Error
Text Type n -- this line executes only if the file does already exist
:CopyDone

FYI, be aware that the Windows 7 experience is quite different - you'd need to wait for a different window title (Copy File), and you'd use this code to replace the Text Type n line

Text Type (Simulate Keystrokes): <ARROW UP><ARROW UP><ARROW UP><ENTER>

Link to comment
Share on other sites

You can also write a second helper macro.

............................................................

I had a client where a "DNA Patient" nag box would randomly appear during execution. Waiting for it in all the possible places slowed things down way too much and I would have had to create the several lines of handler code in hundreds of places. So instead I toyed with a helper macro. It was activated by the window title and would simply click OK whenever it appeared. This allowed the main macro to continue unfettered. The macro would be enabled at the beginning of the parent and disabled at the end. For other reasons I was not able to use it but in testing it worked perfectly.

 

BTW you really should try and use the file manipulation commands. If you do that you can utilize the If File Exists" logic and avoid this problem.

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