How to learn to write macros

How to learn to write macros
How to learn to write macros

Video: Learn Macros in 7 Minutes (Microsoft Excel) 2024, July

Video: Learn Macros in 7 Minutes (Microsoft Excel) 2024, July
Anonim

Creating a macro in any Office application is an automation of a command or a set of commands that you have to execute many times and which become a time-consuming routine. Macros save this time and prevent your work from becoming monotonous.

Instruction manual

one

When working with text, tables, or other Office objects, situations often arise when you need to do the same set of actions. This is not only time-consuming, but also very annoying. Fortunately, macros exist to solve this problem.

2

The VBA software environment is designed to create macros, but you do not have to be a programmer and learn Visual Basic for Application to learn how to write them. For this, there are specially designed tools that, at your command, create VBA code, without requiring additional knowledge from you. However, to learn this language is not so difficult.

3

Macros are created in applications by writing tools. In this case, a certain key combination is assigned the desired sequence of actions. Open the Office app. Select the fragment to be formatted.

4

Select the menu item "Tools" -> "Macro" -> "Start Recording" (in Office 2007 - "View" -> "Macros" -> "Record Macros"). In the appeared window "Macro Record" specify the name of the new macro, by default it costs "Macro1", but it is better to give it a name, especially if there are several macros. The maximum size of the name field is 255 characters, the use of period and space characters is not allowed.

5

Decide on the choice of a button or key combination by which your macro will work in the future. Try to choose the most convenient option, especially if it is intended for frequent use. Select the appropriate item in the "Assign Macro" field: "button" or "keys."

6

If you select the "button", the "Quick Selection Settings" window opens. When choosing the "keys", just enter the combination on the keyboard. Check out Current Combinations to avoid recurrence. Click Assign.

7

Macros created in Word and PowerPoint will be valid for all documents in the future. To make the macro in Excel accessible for all documents, save it in the personal.xls file, which starts automatically when you open the application. Run the command "Window" -> "Display" and select the line with the name of the personal.xls file in the window that appears.

eight

Enter a short description of the macro in the Description field. Click OK and you will be returned to your document, but now you can see the record icon on the mouse cursor. Format the selected text with the sequence of actions you want to automate. Be very careful and do not do unnecessary actions, as the macro will record them all, and this will affect the time it will be executed in the future.

9

Run the command "Tools" -> "Macro" -> "Stop Recording". You created a VBA object without writing a single line of code yourself. However, if you still need to make changes manually, enter the object through the "Macros" section, the "Change" command, or by pressing Alt + F8.

Collection of ready-made VBA macros