terrypin Posted February 13, 2010 Report Share Posted February 13, 2010 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 Quote Link to comment Share on other sites More sharing options...
paul Posted February 13, 2010 Report Share Posted February 13, 2010 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> Quote Link to comment Share on other sites More sharing options...
terrypin Posted February 13, 2010 Author Report Share Posted February 13, 2010 Thanks Paul, that's far better! I'm getting rusty - forgotten all about those neat On Error commands. -- Terry, East Grinstead, UK Quote Link to comment Share on other sites More sharing options...
Cory Posted February 19, 2010 Report Share Posted February 19, 2010 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. 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.