Sei sulla pagina 1di 18

Create A Macro

Macro
an action or a set of actions that you can run as many
times as you want.
you are recording your mouse clicks and keystrokes.
After you create a macro, you can edit it to make minor
changes to the way it works.

Activation For Macro


Before you record a macro
Make sure the Developer tab is visible on the ribbon. By
default, the Developer tab is not visible, so do the following:
Click the File tab, click Options and then click the
Customize Ribbon category.
Under Customize the Ribbon, in the Main Tabs list, click
Developer, and then click OK.

Create Shortcut key


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.
NoteThe shortcut key will override any equivalent default
Excel shortcut key while the workbook that contains the macro
is open.

Store Macro In List


select the workbook where you want to store the macro.
TipIf you want a macro to be available whenever you
use Excel, select Personal Macro Workbook. When
you select Personal Macro Workbook, Excel creates a
hidden personal macro workbook (Personal.xlsb) if it
does not already exist, and saves the macro in this
workbook.

Create Name For Macro


In the Macro name box, enter a name for the macro.
NoteThe first character of the macro name must be a letter.
Subsequent characters can be letters, numbers, or underscore
characters. Spaces cannot be used in a macro name; an
underscore character works well as a word separator. If you
use a macro name that is also a cell reference, you may get
an error message that the macro name is not valid.

In the Description box, type a description of the


macro.
Click OK to start recording.

Record A Macro

Red Shape Button


In Excel, Macro recording can be started by clicking on
the Red Shape button marked in the bottom bar of the
Excel in left hand side.

Record Macro Button

Enter the suitable name for this Macro.

You can also specify the shortcut key for running this
particular recorded macro.

It means on pressing that


particular shortcut-key, this
macro will automatically
run.

Storing Macro

Macros can be stored in either of two locations, as follows:

The workbook you are


using, (will be embedded
even if you e-mail to
another user) or
Your Personal Macro
Workbook (it will always be
available in all of your Excel
workbooks

Create New Macro With Part Of


Existing Macro
Open the workbook that contains the macro that you want to copy.
On the Developer tab, in the Code group, click Macros.
In the Macro name box, click the name of the macro that you want to copy.
Click Edit.
In the code window of the Visual Basic Editor, select the lines of the macro that you want to
copy.
On the Edit menu, click Copy.
TipYou can also right-click and then click Copy, or you can press CTRL+C.
In the Procedure box of the code window, click the module where you want to place the
code.
On the Edit menu, click Paste.
TipYou can also right-click and then click Paste, or you can press CTRL+V.
TipYou 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.

Assign A Macro To An Object,


Graphic, Or Control
On a worksheet, right-click the object, graphic, or
control to which you want to assign an existing macro,
and then click Assign Macro.
In the Macro name box, click the macro that you want to
assign.

Delete A Macro
Do one of the following:
Open the workbook that contains the macro that you want to delete.
If the macro that you want to delete is stored in the personal macro workbook
(Personal.xlsb), and this workbook is hidden, do the following to unhide the
workbook:
On the View tab, in the Window group, click Unhide.
Under Unhide workbooks, click PERSONAL, and then click OK.

On the Developer tab, in the Code group, click Macros.

In the Macros in list, select the workbook that contains the macro that you
want to delete. For example, click This Workbook.
In the Macro name box, click the name of the macro that you want to
delete.
Click Delete.

Run The Macro

Run A Macro By Clicking A Button


On The Quick Access Toolbar
1.Click the File tab, Options, and then click Quick Access Toolbar.
2.In the Choose commands from list, select Macros.
3.In the list, click the macro that you created, and then click Add.
4.To change the button image of the macro, select the macro in the box to
which it was added, and then click Modify.
5.Under Symbol, click the button image that you want to use.
6.To change the name of the macro that is displayed when you rest the
pointer on the button, in the Display name box, type the name that
you want to use.
7.Click OK to add the macro button to the Quick Access Toolbar.
8.On the Quick Access Toolbar, click the macro button that you just
added.

Run A Macro By Clicking An Area On


A Graphic Object
In the worksheet, insert a graphic object, such as a picture, clip
art, shape, or SmartArt.
On the existing object, on the Insert tab, in the Illustrations
group, click Shapes, select the shape that you want to use, and
then draw that shape on the existing object.

Right-click the hot spot that you created, and then click Assign
Macro.
To assign an existing macro to the graphic object, double-click
the macro or enter its name in the Macro name box.

To record a new macro to assign to the selected graphic object, click Record, type
a name for the macro in the Record Macro dialog box, and then click OK to begin
recording your macro. When you finish recording the macro, click Stop Recording
Button image on the Developer tab in the Code group.
Tip

You can also click Stop Recording Button image on the left side of the status bar.

To edit an existing macro, click the name of the macro in the Macro name box,
and then click Edit.
Click OK.
In the worksheet, select the hot spot. This displays the Drawing Tools, adding a
Format tab.
On the Format tab, in the Shape Styles group, click the arrow next to Shape Fill,
and then click No Fill.

Click the arrow next to Shape Outline, and then click No Outline.

Create An Auto-open Macro


If you want to save the macro with a particular workbook,
open that workbook first.
On the Developer tab, in the Code group, click Record Macro.
In the Macro name box, type Auto_Open.
In the Store macro in list, select the workbook where you
want to store the macro.
Click OK, and then perform the actions that you want to
record.
On the Developer tab, in the Code group, click Stop
Recording Button image.

Potrebbero piacerti anche