Excel 简明教程

Using Macros in Excel 2010

Macros in MS Excel

宏使您可以自动处理 Excel 2010 中几乎可以执行的任何任务。通过使用 View Tab » Macro Dropdown 中的宏录制器来记录您例行执行的任务,您不仅会显著加快该过程,而且还能确保每次执行任务时任务中的每个步骤都以相同的方式执行。

Macros enable you to automate almost any task that you can undertake in Excel 2010. By using macro recorder from View Tab » Macro Dropdown to record tasks that you perform routinely, you not only speed up the procedure considerably but you are assured that each step in a task is carried out the same way each and every time you perform a task.

若要查看宏,请选择 View Tab » Macro dropdown

To view macros choose View Tab » Macro dropdown.

view macros

Macro Options

“视图”选项卡包含一个“宏”命令按钮,下拉菜单中包含以下三个选项。

View tab contains a Macros command button to which a dropdown menu containing the following three options.

  1. View Macros − Opens the Macro dialog box where you can select a macro to run or edit.

  2. Record Macro − Opens the Record Macro dialog box where you define the settings for your new macro and then start the macro recorder; this is the same as clicking the Record Macro button on the Status bar.

  3. Use Relative References − Uses relative cell addresses when recording a macro, making the macro more versatile by enabling you to run it in areas of a worksheet other than the ones originally used in the macro’s recording.

Creating Macros

您可以通过以下两种方式之一创建宏−

You can create macros in one of two ways −

  1. Use MS Excel’s macro recorder to record your actions as you undertake them in a worksheet.

  2. Enter the instructions that you want to be followed in a VBA code in the Visual Basic Editor.

现在,我们创建一个简单的宏,它将自动化使单元格内容加粗并应用单元格颜色的任务。

Now let’s create a simple macro that will automate the task of making cell content Bold and apply cell color.

  1. Choose View Tab » Macro dropdown.

  2. Click on Record Macro as below.

record macro
  1. Now Macro recording will start.

  2. Do the steps of action, which you want to perform repeatedly. Macro will record those steps.

  3. You can stop the macro recording once done with all steps.

stop recording

Edit Macro

您可以随时编辑创建的宏。编辑宏将使您转到 VBA 编程编辑器。

You can edit the created Macro at any time. Editing macro will take you to the VBA programming editor.

Edit macros