Many people must know about macros and may have used macros. What is Macros? A macro is a program compiled by VBA. It is a series of commands and functions stored in the Visual Basic module and can be run at any time when the task needs to be executed. How to start learning VBA? This is one of the frequently asked questions of many friends. I personally think that the best way to learn something is to start with interest. This is why this post is created. The following content may not be of practical use in your work and life, but I hope that the content will attract your interest in VBA programming. I think the first step is to start recording macros.
What is a recording macro? Recording macros are a function of Excel. They can convert user operations into code, so that even if you do not know programming at all, you can use recording macros to generate a macro! This function is available in the tool menu/development. Click record new macro, and select the saved place (Personal macro workbook/current workbook or new workbook). Then, as long as you operate Excel according to our normal operation process, after finishing, press stop recording macro to end, in this way, a macro sequence can be generated.
What are the functions of recording Macros? In addition to generating a macro, we can also convert the operating program into a macro, and then use its code to understand the attributes and methods to be used in this process, this is one of the best self-learning methods for beginners.
Where can I see the macro code? We recorded the macros. Where can we see the macro code we recorded? Click the tool/macro/VBA editor or press Alt + F11 to enter the VBA Editor, where you can see the recorded code.
How to run a macro? From tools/macros, you can select the name to run our macros. Of course, you can also run Macros in the VBA editor, first move the cursor to the Code where the macro is located, then click Run sub-process or form in the running menu, or press the corresponding button in the toolbar, or press the shortcut key F5, you can run the sub-process !!! The macro cannot cancel all operations on the file. Before learning about the macro function, the best way is to save the file (better back up the file) and then run the macro, if you find that the macro operation result is incorrect, you can close the file without saving it. In this way, you can open the file and restore it to the state before running the macro (Note: The macro can also save the file on its own, in this case, this method is invalid)