Frank Posted May 12, 2023 Report Share Posted May 12, 2023 I'm back...HELP...please I wrote a macro that uses / sets a lot of variables THEN goes to specific WINDOWS and performs functions / actions. I prep the computer by opening the number of WINDOWS I need (usually 5) and I name them... 111,222,333,444,555 (the names can be anything) The macro is written so that I set the variables before running the macro. and the Macro is one big REPEAT. Goes to window 111 does functions then goes to 222 does functions etc. The Macro REPEATS until a specific action happens or takes place MY QUESTION... is there a way to set an additional variable (prompt for value) for the number of WINDOWS I have and have the macro repeat (go to the next variable window (111 then 222 then...etc) so that I don't have to copy my code five times in the macro? Whit the right commands my 350 line macro would come down to 70-80 lines of code... I believe the steps would start with... Set Integer variable %STOP% to 0 Prompt for value / store a variable WINDOWS (When I run the macro it would ask how many windows do I have open) (I would still have to open the windows and name them prior to running the macro) REPEAT START - Repeat until variable %STOP% = 1 THE commands that go here is what I am looking for. Besides getting rid of a lot of lines of code, this would be helpful because whenever I have to change a line or lines of code in the macro I have to change it 5 times / in each section for the respective window. Any help would be extremely appreciated!!! F Macro- Beginning commands set a number of variables... Macro starts... ACTIVATE Window 111 command command etc, 68 commands Activate Window 222 command command etc, 68 commands Activate window 333 command command etc, 68 commands etc Quote Link to comment Share on other sites More sharing options...
rberq Posted May 12, 2023 Report Share Posted May 12, 2023 Put the common (repeated) commands into a second macro, and call the second macro from the first with the "Macro Run" command. "Macro One" - Beginning commands set a number of variables... Be sure to "Make these variables available to macros called by this macro" (check box when defining the variables) Macro starts... ACTIVATE Window 111 Macro Run "Macro Two" Activate Window 222 Macro Run "Macro Two" Activate window 333 Macro Run "Macro Two" End of "Macro One" "Macro Two" - command command etc, 68 commands etc End of "Macro Two" Quote Link to comment Share on other sites More sharing options...
Frank Posted May 13, 2023 Author Report Share Posted May 13, 2023 WOW, Never even thought of two macros!!! I will work on that. I have been playing out the steps in my head over and over AND I THINK THAT WILL WORK. thus allowing me to make changes only Macro 2... Nice! thanks, F (I will report back after implementing...) Quote Link to comment Share on other sites More sharing options...
Frank Posted May 14, 2023 Author Report Share Posted May 14, 2023 RBERQ, QUESTION... Once I obtain a desired result I have the macro STOP. with your suggestion I am running a macro within a macro so, Currently my macro stops within the lines of code that will be in MACRO 2 Will that stop MACRO 1 automatically? if not how would you suggest to stop everything Macro1 and Macro 2? Thanks, F Quote Link to comment Share on other sites More sharing options...
acantor Posted May 14, 2023 Report Share Posted May 14, 2023 Let's say you have a macro called "Test" that consists of three instructions: Macro Run: Test1 Macro Run: Test2 Macro Run: Test3 When you trigger "Test," Test1 will run. Then Test2. And finally, Test3. However, if Test1, Test2, or Test3 contains this instruction: Macro Stop Then Test will stop at the point the instruction is encountered. For example, here are three macros: Test1: Text Box Display: This is Test1 --------------- Test2: Text Box Display: This is Test2 Macro Stop --------------- Test3: Text Box Display: This is Test3 If you run Test, you'll see the first Text Box, the second Text Box, but not the third. Quote Link to comment Share on other sites More sharing options...
Frank Posted May 14, 2023 Author Report Share Posted May 14, 2023 Thanks to everyone in the forum. The help has been spot on! acantor, Thank you for the explanation. I understood it... I tested my macro... It stopped when it was supposed to! Rberq, The two macros work great together. after creating / splitting them I had to make numerous changes and it was very easy to do!!! Also, I was able to cut the size of the macro by 2/3. thanks again! F 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.