Вы находитесь на странице: 1из 17

Microsoft Excel 2007: Create a macro by using Microsoft Visual Basic

Add to Favorites

In Microsoft Excel 2007, macros can be created using Microsoft Visual Basic. The following will show you how to create a macro using Microsoft Visual Basic: 1. If the Developer tab is unavailable, complete the following to display it: a. Click the Microsoft Office Button, and then click Excel Options. b. In the Popular category, under Top options for working with Excel, choose the Show Developer tab in the Ribbon check box, and then click OK.

2. To set the security level temporarily to enable all macros, complete the following instructions: a. On the Developer tab, in the Code group, click Macro Security.

b. Under Macro Settings, click Enable all macros (not recommended, potentially dangerous code can run), and then click OK.

Note: To help prevent dangerous code from running, it is recommend that you return to any of the settings that disable all macros after you are finished working with macros. 3. On the Developer tab, in the Code group, click Visual Basic.

4. If needed, on the Insert menu, click Module.

Note: Modules are automatically created for all sheets in the workbook.

5. In the code window of the module, type or copy the macro code that you want to use. 6. To run the macro from the module window, press F5. 7. On the File menu, click Close and Return to Microsoft Excel when you finish writing the macro.

Microsoft Excel 2007: Assign a macro to an object, graphic, or control

Add to Favorites

There are many new features available in Microsoft Excel 2007. One of the neat things you can do in it is assign a macro to an object, graphic, or control. The following will show you how to do it.

1. On a worksheet, right-click the object, graphic, or control to which you want to assign an existing macro, and then click Assign Macro on the shortcut menu.

2. In the Macro name box, click the macro that you want to assign.

Microsoft Excel 2007: Copy part of a macro to create

Add to Favorites

another macro
With Microsoft Excel you can copy part of a macro to create another one. 1. If the Developer tab is unavailable, follow the instructions below to display it: a. Click the Microsoft Office Button, and then click Excel Options.

b. In the Popular category, under Top options for working with Excel, select the Show Developer tab in the Ribbon check box, and then click OK.

2. To set the security level temporarily to enable all macros, follow the instructions below: a. On the Developer tab, in the Code group, click Macro Security.

b. Under Macro Settings, click Enable all macros (not recommended, potentially dangerous code can run), and then click OK.

Note: To help prevent dangerous code from running, it is recommend that you return to any of the settings that disable all macros after you finish working with macros. 3. Open the workbook that contains the macro that you want to copy. 4. On the Developer tab, in the Code group, click Macros.

5. In the Macro name box, click the name of the macro that you want to copy. 6. Click Edit. 7. In the code window of the Visual Basic Editor, select the lines of the macro that you want to copy. Note: To copy the entire macro, include the Sub and End Sub lines in the selection. 8. On the Edit menu, click Copy. Note: You can also right-click and then click Copy on the shortcut menu, or you can press CTRL+C. 9. In the Procedure box of the code window, click the module where you want to place the code. 10. On the Edit menu, click Paste. Note: You can also right-click and then click Paste on the shortcut menu, or you can press CTRL+V. You cannot edit your Personal Macro Workbook file (Personal.xlsb) because it is a hidden workbook that is always open. You must first unhide it by using the Unhide command. You can also open it in the Visual Basic Editor by pressing ALT+F11.

Microsoft Excel 2007: Delete a macro

Add to Favorites

Macros are a common tool used in Microsoft Excel 2007. If you have a macro, it is possible to delete by doing the following: 1. Open the workbook that contains the macro that you want to delete. 2. On the Developer tab, in the Code group, click Macros.

Note: If the Developer tab is not available, do the following to display it: a. Click the Microsoft Office Button , and then click Excel Options. b. In the Popular category, under Top options for working with Excel, select the Show Developer tab in the Ribbon check box, and then click OK.

3. In the Macros in list, select This Workbook. 4. In the Macro name box, click the name of the macro that you want to delete. 5. Click Delete.

Microsoft Excel 2007: How to

Add to Favorites

Enable Macros
This article describes how to enable macros in Microsoft Excel 2007 spreadsheets.

Macros in Microsoft Excel 2007 serve as modules of instructions that tell Excel to automatically perform a particular process or set of processes. Macros can be extremely useful in performing a wide variety of tasks. However, the same versatility that makes macros such useful tools also enables them to cause serious damage to a user's computer if a macro containing poorly written or malicious code is allowed to run. For this reason, macros are not enabled by default in Excel 2007; it is highly recommended that you verify that the macros you are attempting to enable come from a trustworthy source before continuing past this point. To enable macros in Microsoft Excel 2007, take the following steps: 1. Open Excel 2007 and click the Office button in the upper left corner of the screen. At the bottom of this menu, click the Excel Options button.

2. Click the Trust Center button on the left. Then, at the bottom right, select Trust Center Settings.

3. In the new window that appears, choose Macro Settings from the sidebar and select Disable all macros with notification from the list of options that appear. This option keeps macros disabled but notifies users when macros attempt to run, allowing users to decide on a case-bycase basis which macros to enable. Click OK to exit this window.

4. For the new settings to take effect, it will be necessary to close Excel and reopen it. A security dialog box should appear beneath the Office ribbon the next time you attempt to run a spreadsheet that contains macros.

5. When the notification appears, click the Options button. Choose Enable this content from the options that appear to allow macros to run within the current spreadsheet. Click OK to close the window.

Microsoft Excel 2007: Record a Macro

Add to Favorites

To automate repetitive tasks, users can quickly record a macro in Microsoft Office Excel. Users also have the ability to create a macro by using the Visual Basic Editor in Microsoft Visual Basic to write their own macro script, or to copy all or part of a macro to a new macro. After users create a macro, they can assign it to an object (such as a toolbar button, graphic, or control) so that they can run it by clicking the object. If they no longer need to use a macro, users can delete it. When recording a macro, all the steps are recorded by the macro recorder. Navigation on the Ribbon is not included in the recorded steps. 1. If the Developer tab is not available, do the following to display it: a. Click the Microsoft Office Button, and then click Excel Options.

b. In the Popular category, under Top options for working with Excel, select the Show Developer tab in the Ribbon check box, and then click OK.

2. To set the security level temporarily to enable all macros, do the following: a. On the Developer tab, in the Code group, click Macro Security.

b. Under Macro Settings, click Enable all macros (not recommended, potentially dangerous code can run), and then click OK.

3. On the Developer tab, in the Code group, click Record Macro.

4. In the Macro name box, enter a name for the macro.

NOTE: The first character of the macro name must be a letter. Following characters can be letters, numbers, or underscore characters. Spaces are not allowed in a macro name; an underscore character works well as a word separator. When using a macro name that is also a cell reference, users may get an error message that the macro name is not valid. 5. To assign a CTRL combination shortcut key to run the macro, in the Shortcut key box, type any lowercase letter or uppercase letter that you want to use. NOTE: The shortcut key will override any equivalent default Excel shortcut key while the workbook that contains the macro is open. 6. In the Store macro in list, select the workbook in which you want to store the macro.

7. To include a description of the macro, in the Description box, type the text that you want. 8. Click OK to start recording. 9. Perform the actions that you want to record. 10. On the Developer tab, in the Code group, click Stop Recording.

Microsoft Excel 2007: Saving macros to the Personal Macro Workbook

Add to Favorites

Some helpful articles include: Microsoft Excel 2007: Overview Microsoft Excel 2007: Delete a macro Microsoft Excel 2007: Assign a macro to an object, graphic, or control

Microsoft Excel 2007 allows users to store macros in a Personal Macro Workbook similar to the personal.xls file in MS Excel 2003. Macros stored in this file can be used in all workbooks as opposed to just the workbook it was created in. Complete the following steps to store a macro in the Personal Macro Workbook in Microsoft Excel 2007. 1. Click Record Macro under the Developer tab in Excel. Refer to GROK article 538 to find out how to get the Developer tab.

2. In the Record Macro dialog box, choose Personal Macro Workbook under Store macro in.

3. Fill in the other sections of the dialog box, and click OK.

Record the macro after completing the steps above. Refer to GROK article 537 to find out how to record macros. The resulting macro can be used in all workbooks.

Вам также может понравиться