drdave Posted October 9, 2017 Report Share Posted October 9, 2017 I need some assistance. I have 545 macros that employ a "windows activate" command to an old database. The database name has changed. So I have to go into each macro and edit it using the "Find and Replace all" command each time for 545 times. I have tried to write a macro that would accomplish this goal using a hot key. But it does'nt appear to work. I tried, while in the Macro Express Pro - Explorer, to write a macro that go one-by-one to the next macro below it and: arrow down (to go to the macro below it) enter (to edit the macro) CRTL r (find and replace the two database's names) ALT a (find and replace all) Activate "Replace" box; move mouse to "x" and close "replace box" CTRL l to save and close. I would then have the macro repeat itself 545 times. Some assistance in the best way to accomplish this would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
Cory Posted October 9, 2017 Report Share Posted October 9, 2017 That's a hard one. I think Terry has more experience with this. One thing that I suggest is that you never use Magic Numbers. That is to say, things like this shouldn't be hard coded. You should keep them as a setting in an INI file or something. I prefer to use the Windows Registry. I'm sure by now you can see the reason why. Quote Link to comment Share on other sites More sharing options...
drdave Posted October 9, 2017 Author Report Share Posted October 9, 2017 Cory. Thanks for your quick reply. Of course you are right but I’ve been building on this group long before I understood the details of huge and involved macros. I was hoping for a short fix, thanks again. Quote Link to comment Share on other sites More sharing options...
rberq Posted October 9, 2017 Report Share Posted October 9, 2017 I think you are on the right track, and I see no reason why your approach shouldn’t work. Your fixit macro should be able to do all the following with keystrokes (which are easier than figuring out where and when to click the mouse). Be sure to insert reasonable time delays between the Text Type functions, so your commands don’t outrun the Explorer and Editor functions. Set Keystroke Speed to a reasonable value. Arrow down (in Explorer) to next macro. Enter (to edit the macro). Alt-v followed by i to enter the Direct Editor. Ctrl-R followed by appropriate values to set the replacement, followed by Tabs to highlight the Replace All button, and ENTER to do the replacement. ESC a couple times to close the replace dialog box and the “not found” box if any. Alt-s followed by l to save/close/return to macro explorer. Like Cory said, don’t rely on magic numbers. No way would I start this macro and ask it to run 545 times. Too much can go wrong, mostly in terms of Windows timing, and once your macro is out of sync with ME Explorer, who knows what havoc you may wreak? I’d suggest making a good backup of your macro file, and letting the macro repeat ten or twenty times maximum, requiring you to restart it for additional iterations. Quote Link to comment Share on other sites More sharing options...
acantor Posted October 10, 2017 Report Share Posted October 10, 2017 Been there, done that! I think this is a mistake all macro scripters have made. A "repair macro" to update all of your scripts is certainly doable. I use dozens of Macro Express macros that run only in Macro Express, so there is nothing to prevent you from trying to automate the task. But be aware that you may reach the point of diminishing returns if the time it takes to automate the process takes longer than manually fixing the scripts. But if it were me, I would try! I totally agree with rberq: don't try to do everything in one go. Start modestly, maybe 10 or 20 scripts at a time; and if you discover your repair macro is working reliably, then up the number of repetitions. You can increase the reliability a bit by pressing Esc to close the Replace dialog instead of clicking on the Close icon. Adding delays between steps, even 100 or 200 ms, might help. Longer delays will likely be helpful when windows and/or dialog boxes are opening and closing, maybe 300 ms or 500 ms. This might be the perfect moment to rewrite your script in ways that would simplify the task of updating the scripts in the future! Quote Link to comment Share on other sites More sharing options...
Cory Posted October 10, 2017 Report Share Posted October 10, 2017 I requested a feature to find and replace in multiple macros. 1 Quote Link to comment Share on other sites More sharing options...
terrypin Posted November 16, 2017 Report Share Posted November 16, 2017 Sorry I'm late to contribute. Like acantor, despite my apprehension about screwing it up I usually forge ahead and write Find/Replace macros for macros. Typically this is after a major file restructuring. With the sort of care that has been suggested, it can be a big time saver IMO. (And, anyway, it's usually a challenge I find hard to resist.) In rare cases I've been able to use a hex editor on all my macros in one operation, which is very satisfying. But those were limited to replacing one string with another of exactly the same length. Too much to hope that this applies to your old and new database names? One extremely handy tool I sometimes use is based closely on a macro Cory developed years ago called Search and report on macro text. It only Finds specified strings, not replace them, but its output in my text editor lists all in convenient form. I've even occasionally written temporary macros that then operate on that list, opening the target macro and then making the required replacement. But I loudly echo Cory's desire for a built-in, global Find/Replace! Terry, East Grinstead, UK Quote Link to comment Share on other sites More sharing options...
Samrae Posted November 16, 2017 Report Share Posted November 16, 2017 Has anyone tried to edit macros in the Direct Editor instead of the Script Editor? I haven't had the need to do this yet but it seems like one approach that may work. A Ctrl+R brings up a Find and Replace dialog in the Direct Editor. If you need more powerful editing tools you could open a macro in the Direct Editor, copy it to the clipboard, paste into a text editor, make changes, and then copy from the text editor and paste it back into the direct editor. This is not a substitute for a global Find/Replace. Quote Link to comment Share on other sites More sharing options...
rberq Posted November 16, 2017 Report Share Posted November 16, 2017 55 minutes ago, Samrae said: Has anyone tried to edit macros in the Direct Editor instead of the Script Editor? See my post earlier in this thread. I should have highlighted the phrase Direct Editor so it would stand out. The approach worked for me, but I haven't used it extensively. Quote Link to comment Share on other sites More sharing options...
terrypin Posted November 16, 2017 Report Share Posted November 16, 2017 Yes, I often use the Direct Editor. BTW, it seemed mandatory when I was using the Run Macro in Variable command some months ago. Quote Link to comment Share on other sites More sharing options...
Samrae Posted November 16, 2017 Report Share Posted November 16, 2017 4 hours ago, rberq said: See my post earlier in this thread. I should have highlighted the phrase Direct Editor so it would stand out. No, I should have read more carefully! 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.