Macros provide a very simple way to program Audacity. A macro is just a list of commands. There are no “loops” or “conditional statements” or other features found in more complex programming languages - it’s just a list that starts with the first command and steps through the list to the end.
More complex programming requires a programming language that has more features than a macro.
Audacity includes a suitable language for more complex programming tasks, called “Nyquist”.
Nyquist is a full featured scripting language, and it can run the same commands as macros, but with much more flexibility.
Example - to export the current project to multiple files: