+ All Categories
Home > Documents > Attach a Macro Command to a Button

Attach a Macro Command to a Button

Date post: 03-Apr-2018
Category:
Upload: prasoon-singh
View: 222 times
Download: 0 times
Share this document with a friend
75
Attach a macro command to a button It's sometimes very interesting to be able to execute macro commands by just pressing a button; ev en more if yo leave your file to another person. They probably don't know all the macro commands that you created to work fa The next exercise consists in attaching a macro command to a button. IMPORTANT: You must already have created a macro that you will need before attaching it to a button. From the Edit menu, select the Toolbar option. From the list of the available toolbars, select the Forms toolbar. This toolbar offers you several objects, or controls, that you can place on forms. For the moment, you only have worry about the button to attach a macro command. Press the button. Press the left mouse button and determine the place and size of the button. When satisfied with the size, release the left mouse button. Excel will automatically ask you for the n ame of the macro that you want to attach to the newl y created button. Move the toolbar if it's necessary. Place the cursor on the titles bar of the toolbar (the blue bar on top). Press the left mouse button and move the toolbar towards the place of your choice. Once the toolbar is at its new location, release the left mouse button. This toolbar is used for creating forms in Excel files. It facilitates the use of the model for the users.
Transcript

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 1/75

Attach a macro command to a button

It's sometimes very interesting to be able to execute macro commands by just pressing a button; even moleave your file to another person. They probably don't know all the macro commands that you created to

The next exercise consists in attaching a macro command to a button.

IMPORTANT: You must already have created a macro that you will need before attaching it to a button

From the Edit menu, select the Toolbar option.From the list of the available toolbars, select the Forms toolbar.

This toolbar offers you several objects, or controls, that you can place on forms. For the moment, you on

worry about the button to attach a macro command.

Press the button.Press the left mouse button and determine the place and size of the button.

When satisfied with the size, release the left mouse button.

Excel will automatically ask you for the name of the macro that you want to attach to the newly created b

Move the toolbar if it's necessary.

Place the cursor on the titles bar of the toolbar (the blue bar on top).Press the left mouse button and move the toolbar towards the place of your choice.

Once the toolbar is at its new location, release the left mouse button.

This toolbar is used for creating forms in Excel files. It facilitates the use of the model for the

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 2/75

 

Select the macro of your choice.Press the OK button.

While the button is still selected, you can change the text on the button to whatever you need it to be.

Once finished, click outside of the button.

To execute the macro that's now connected to the button. 

Place the cursor in the A5 cell.

Place the cursor over the button.Press the left mouse button.

The button now executes the macro. You can apply any macro that you make to a button. It's that easy!

If you wish to change the options of the button. 

Place the cursor over the button.Press the right mouse button.

A context menu will appear next to the button.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 3/75

 

If you want to affect the presentation of this macro button, select the Format Control option.

The properties window of the button will allow you to change all the options of your choice. All the poss

you will be found under these seven tabs: Font, Alignment, Size, Protection, Properties, Margins and We

Under the Font tab you will find all the options for the presentation of the text on the button. You can ch

font, font style, size, color and effects.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 4/75

 

The Alignment tab allows you to change the placement of the text inside the button including its' orienta

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 5/75

 

The Size tab allows you to determine exactly the size of the button on the worksheet.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 6/75

 

Like for the protection for cells, it's also possible to protect buttons under the Protection tab. By default, buttons are protected when the protection is activated. You should leave it protected unless you want the

able change the button properties for some reason.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 7/75

 

The Properties tab allows you to decide if the button should change size and placement when you changchange you size and placement of the cells of the worksheet below it. You can also decide to move or no

if you insert or delete rows and columns. By default, the button will not be printed unless you activate th

object option.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 8/75

 

The Margins tab allows you to control the margin, or the space between the text on the button and its bocan use the predetermined margins or change them to your choice.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 9/75

 

You can always save this worksheet as a Web page. So Excel offers you some Web properties under the For buttons, it only allows you to put some alternate

Assign a macro to a drawingIt's interesting, even practical, to place a macro on a command button. It's easier for the users to use the o

you prepared them for them. But these buttons lack originality. They're grey! That's why Excel also offer

 possibility of placing a macro on a drawing. With a bit of work, these drawings can have very interestingare some examples.

Before being able to attach a macro to a drawing, you need two things: a drawing and a macro. Let's pres

you already have both. The next part consists only in attaching a macro to a drawing.

Place the cursor over the drawing.

Press the right mouse button.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 10/75

From the context menu, select the Assign macro option.

From the list of macro commands that you have already prepared, select the one of your choice.

Press the OK button.

If you can't select the Assign macro option, click on the border of the drawing instead of the text inside i

should then be able to assign the macro of your choice. You can repeat this operation on as many drawinwant. It certainly puts a little fun in your file!

Assign a macro to a toolbar

Assigning a button to a toolbar can be done in two

Create a new toolbar 

From the View menu, select the options Toolbar and Customize.

Press the New button.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 11/75

Enter the name you wish to give to your new toolbar and press the OK button.

An empty toolbar will appear on the screen. You can now drag any button that you wish to that toolbar; i

macros.

Creating a button for the toolbar

 Now is the time to add buttons that you will be able to place on any toolbar. You just create a new toolba

 buttons in it. This next step will show you how to add buttons to it, or to any toolbar.

Select the Commands tab.

From the Categories group, select Macros.Drag the Custom Button to your new Toolbar.

The result is that you now have a button on your toolbar. You can drag other button onto it.

Close the Customize toolbar window.

The only thing left to do is to assign a macro to that new button.

Place the cursor over the button.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 12/75

Press the right mouse button.

From the content menu, select the Assign Macro option.

From the list of available macros, select the one you wish to assign to the button.Press the OK button.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 13/75

Let's see if it works.

Place the cursor in the A7 cell.

Press on the button from the new toolbar.

Change button picture

You can now make macros, apply them where you want them and even create toolbars! But it's not over.

 button picture was placed on the toolbar when you added a macro command to it. Excel offers you a list you can use to better represent what your macro command will do.

Place the pointer over the new toolbar button.

Press the right mouse button.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 14/75

 

From the context menu, select the Change Button Image option.

A list of pictures will appear. Select the picture that best represents the action from your macro.

The picture will be replaced. You can change again if you wish.

Edit button picture

The number of pictures you can select from is limited and may not answer your needs. So you can chang pictures or create your own.

Place the pointer over the new toolbar button.Press the right mouse button.

From the context menu, select the Edit Button Image option.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 15/75

 

The size of the picture and the number of colors is limited but not your imagination. You can try any formshade on it, anything you can think!

Once you created the picture you wish, press the OK button.

You can now create you own macros and toolbars. This will help you personalize Excel to better answer

make you more efficient. That's what this site is all about!

Webanalytics provided by

This site is hosted by 1&1.com 

 Navigation

Previous 

 Next Homepage 

FAQ 

What's new 

Excel - Using macros

Introduction Creating a macro command 

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 16/75

Sitemap 

Topics

Introduction 

Basic commands Presentation 

Page layout and printingFunctions 

Copy, Paste and

relative and absolute references 

Charts (graphics) Macro commands 

Analysis tools 

Comments 

Data list 

Pivot table Exercise: creating a model 

Quiz 

Tutorials

Word 

Excel 

PowerPoint 

Access 

Others

Demonstration files 

Texte en français 

Word 2010 Tutorials 

Contact

By e-mail 

Join our Newsletter  

Share this page

Change a macro command 

Print a macro command Assign a macro to a button 

Assign a macro to a drawing 

Assign a macro to a button 

Change button picture Edit button picture

Introduction

A macro command is a series of instructions that are alw

executed one after the other in the same order. They're ve

to automate repetitive tasks. The exercise that follows widemonstrate how to create a macro command. The next m

 basically changes the background color of the selected ce

contains only that single command. But after you've finiswill be able create your own "macros" and insert as many

instructions as you need.

Creating of a macro command

Write the following numbers in the appropriate cells.Place the cursor in the A1 cell.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 17/75

 

0Share 

You must place the cursor in that cell before you can begin your "macro". You'll see why later on.

From the Tools menu, select the Macro option.Select the Record New macro option.

A new window will open asking you for some information about the new macro. The first box asks you f

that you give to this macro. You can also put a letter or a number in the shortcut box. You'll be able to exmacro by pressing the Ctrl and a keys. You can place in any letter or number that you want. The shortcu

compulsory.

The window asks you if you want to store the macro in this file or in another worksheet file. It's possible

the macro commands in a personal macro file. The same macro can then be used for several files. But thi

those that are really serious about using macros.

For the exercise:

Give a name to your macro. It should represent the actions that will be done such as " Printing_the_budgname of the macro cannot have any spaces. An underline can be used to link words. It's also possible to h

shortcut key to activate a macro command. This avoids you having to go into the Tools menu, followed b

Macro, Macro commands, select the macro of your choice and pressing on the Execute button.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 18/75

Enter the data as shown in the picture above.

Press the OK button.

All the actions that you go to make will be added to the macro command until you stop the recording.

As soon as you press the OK button, the window disappears and a small toolbar appears in its place. Thitoolbar has only two buttons. The first one is to stop the macro from recording. The second is to activate

deactivate the relative reference option. This can be important according to the type of macro that you w

out. You do not activate this option if you want the macro to do whatever you want it to do at always the

location. You activate this option if you want the macro to start where the active cursor is located. There details of this option a little later on this page.

Press the second button to be sure that the relative option is activated. (It's very important for this demo

Make a block out of the A1 to C1 cells.

Press the Fill button to change the cell's background color to the color of your choice.

Press the first button of the macro toolbar to stop the macro from recording.

OR 

From the Tools menu, select the Macro and Stop recording options.

The new macro command is now complete. It could have had a lot more instructions than this example. B

only to demonstrate what a macro can do. It's time to see if you may repeat it.

Place the cursor in the A3 cell.Press the Ctrl and A keys to activate the shortcut to the macro.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 19/75

Here is the result of the macro. The cells of the third row have now the same background color as the on

for the cells of the first row.

There is an explanation if it didn't work. You forgot to activate the relative position option when asked. E

repeat the macro at the same location instead of beginning it where the cursor is located. It's as for that re

was asked to you to move the cursor in the A3 cell and to activate the relative button.

Because the relative reference option was activated, you may execute the macro to another place rather th

was created. You just need to put the cursor where you need to activate the macro. If the relative option i

activated, the macro will always repeat itself at the same location.

It can be practical for your needs. It depends on the box. You decide when you should activate the relativoption or not. It's practical when you know that you'll want to apply the macro to another place in your fi

last exercise, it was necessary to be able to apply it to the A3 to C3 cells.

A 1004 error message can also appear. Generally, it's because you forgot to stop the macro command fro

The macro is then caught in an endless loop. The macro is recalled before it's even finished! It will be ne

change the macro.

Change a macro command

From the Tools menu, select the Macro option

Select the macro of your choice and press the Edit button.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 20/75

 

The Visual BASIC editor will appear with the code of the macro command that you want to change.

The macro indicates that three cells were selected (A1 to C1). It then indicates the color as well as the pa

 background of the selected cells.

Print a macro command

It's possible to print the code while changeing the macro command.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 21/75

From the File menu, select the Print option.

To return to Excel... 

From the File menu, select the Close and return to Microsoft Excel option.

Attach a macro command to a button

It's sometimes very interesting to be able to execute macro commands by just pressing a button; even mo

leave your file to another person. They probably don't know all the macro commands that you created to

The next exercise consists in attaching a macro command to a button.

IMPORTANT: You must already have created a macro that you will need before attaching it to a button

From the Edit menu, select the Toolbar option.

From the list of the available toolbars, select the Forms toolbar.

This toolbar offers you several objects, or controls, that you can place on forms. For the moment, you on

worry about the button to attach a macro command.

Move the toolbar if it's necessary.

Place the cursor on the titles bar of the toolbar (the blue bar on top).

Press the left mouse button and move the toolbar towards the place of your choice.

Once the toolbar is at its new location, release the left mouse button.

This toolbar is used for creating forms in Excel files. It facilitates the use of the model for the

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 22/75

Press the button.Press the left mouse button and determine the place and size of the button.When satisfied with the size, release the left mouse button.

Excel will automatically ask you for the name of the macro that you want to attach to the newly created b

Select the macro of your choice.

Press the OK button.

While the button is still selected, you can change the text on the button to whatever you need it to be.

Once finished, click outside of the button.

To execute the macro that's now connected to the button. 

Place the cursor in the A5 cell.

Place the cursor over the button.

Press the left mouse button.

The button now executes the macro. You can apply any macro that you make to a button. It's that easy!

If you wish to change the options of the button. 

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 23/75

Place the cursor over the button.

Press the right mouse button.

A context menu will appear next to the button.

If you want to affect the presentation of this macro button, select the Format Control option.

The properties window of the button will allow you to change all the options of your choice. All the poss

you will be found under these seven tabs: Font, Alignment, Size, Protection, Properties, Margins and We

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 24/75

Under the Font tab you will find all the options for the presentation of the text on the button. You can ch

font, font style, size, color and effects.

The Alignment tab allows you to change the placement of the text inside the button including its' orienta

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 25/75

 

The Size tab allows you to determine exactly the size of the button on the worksheet.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 26/75

 

Like for the protection for cells, it's also possible to protect buttons under the Protection tab. By default, buttons are protected when the protection is activated. You should leave it protected unless you want the

able change the button properties for some reason.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 27/75

 

The Properties tab allows you to decide if the button should change size and placement when you changchange you size and placement of the cells of the worksheet below it. You can also decide to move or no

if you insert or delete rows and columns. By default, the button will not be printed unless you activate th

object option.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 28/75

 

The Margins tab allows you to control the margin, or the space between the text on the button and its bocan use the predetermined margins or change them to your choice.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 29/75

 

You can always save this worksheet as a Web page. So Excel offers you some Web properties under the For buttons, it only allows you to put some alternate

Assign a macro to a drawingIt's interesting, even practical, to place a macro on a command button. It's easier for the users to use the o

you prepared them for them. But these buttons lack originality. They're grey! That's why Excel also offer

 possibility of placing a macro on a drawing. With a bit of work, these drawings can have very interestingare some examples.

Before being able to attach a macro to a drawing, you need two things: a drawing and a macro. Let's pres

you already have both. The next part consists only in attaching a macro to a drawing.

Place the cursor over the drawing.

Press the right mouse button.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 30/75

From the context menu, select the Assign macro option.

From the list of macro commands that you have already prepared, select the one of your choice.

Press the OK button.

If you can't select the Assign macro option, click on the border of the drawing instead of the text inside i

should then be able to assign the macro of your choice. You can repeat this operation on as many drawinwant. It certainly puts a little fun in your file!

Assign a macro to a toolbar

Assigning a button to a toolbar can be done in two

Create a new toolbar 

From the View menu, select the options Toolbar and Customize.

Press the New button.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 31/75

Enter the name you wish to give to your new toolbar and press the OK button.

An empty toolbar will appear on the screen. You can now drag any button that you wish to that toolbar; i

macros.

Creating a button for the toolbar

 Now is the time to add buttons that you will be able to place on any toolbar. You just create a new toolba

 buttons in it. This next step will show you how to add buttons to it, or to any toolbar.

Select the Commands tab.

From the Categories group, select Macros.Drag the Custom Button to your new Toolbar.

The result is that you now have a button on your toolbar. You can drag other button onto it.

Close the Customize toolbar window.

The only thing left to do is to assign a macro to that new button.

Place the cursor over the button.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 32/75

Press the right mouse button.

From the content menu, select the Assign Macro option.

From the list of available macros, select the one you wish to assign to the button.Press the OK button.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 33/75

Let's see if it works.

Place the cursor in the A7 cell.

Press on the button from the new toolbar.

Change button picture

You can now make macros, apply them where you want them and even create toolbars! But it's not over.

 button picture was placed on the toolbar when you added a macro command to it. Excel offers you a list you can use to better represent what your macro command will do.

Place the pointer over the new toolbar button.

Press the right mouse button.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 34/75

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 35/75

 

The size of the picture and the number of colors is limited but not your imagination. You can try any formshade on it, anything you can think!

Once you created the picture you wish, press the OK button.

You can now create you own macros and toolbars. This will help you personalize Excel to better answer

make you more efficient. That's what this site is all about!

Webanalytics provided by

This site is hosted by 1&1.com 

Change button picture

You can now make macros, apply them where you want them and even create toolbars! But it's not over. button picture was placed on the toolbar when you added a macro command to it. Excel offers you a list

you can use to better represent what your macro command will do.

Place the pointer over the new toolbar button.

Press the right mouse button.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 36/75

 

From the context menu, select the Change Button Image option.

A list of pictures will appear. Select the picture that best represents the action from your macro.

The picture will be replaced. You can change again if you wish.

Edit button picture

The number of pictures you can select from is limited and may not answer your needs. So you can chang pictures or create your own.

Place the pointer over the new toolbar button.Press the right mouse button.

From the context menu, select the Edit Button Image option.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 37/75

 

The size of the picture and the number of colors is limited but not your imagination. You can try any formshade on it, anything you can think!

Once you created the picture you wish, press the OK button.

You can now create you own macros and toolbars. This will help you personalize Excel to better answer

make you more efficient. That's what this site is all about!

Webanalytics provided by

This site is hosted by 1&1.com 

Introduction

A macro command is a series of instructions that are always executed one after the other in the same ordvery practical to automate repetitive tasks. The exercise that follows will demonstrate how to create a macommand. The next macro basically changes the background color of the selected cells. It contains only

command. But after you've finished, you will be able create your own "macros" and insert as many instru

you need.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 38/75

Creating of a macro command

Write the following numbers in the appropriate cells.Place the cursor in the A1 cell.

You must place the cursor in that cell before you can begin your "macro". You'll see why later on.

From the Tools menu, select the Macro option.Select the Record New macro option.

A new window will open asking you for some information about the new macro. The first box asks you f

that you give to this macro. You can also put a letter or a number in the shortcut box. You'll be able to ex

macro by pressing the Ctrl and a keys. You can place in any letter or number that you want. The shortcu

compulsory.

The window asks you if you want to store the macro in this file or in another worksheet file. It's possible

the macro commands in a personal macro file. The same macro can then be used for several files. But thi

those that are really serious about using macros.

For the exercise:

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 39/75

Give a name to your macro. It should represent the actions that will be done such as " Printing_the_budg

name of the macro cannot have any spaces. An underline can be used to link words. It's also possible to h

shortcut key to activate a macro command. This avoids you having to go into the Tools menu, followed b

Macro, Macro commands, select the macro of your choice and pressing on the Execute button.

Enter the data as shown in the picture above.Press the OK button.

All the actions that you go to make will be added to the macro command until you stop the recording.

As soon as you press the OK button, the window disappears and a small toolbar appears in its place. Thi

toolbar has only two buttons. The first one is to stop the macro from recording. The second is to activate

deactivate the relative reference option. This can be important according to the type of macro that you wout. You do not activate this option if you want the macro to do whatever you want it to do at always the

location. You activate this option if you want the macro to start where the active cursor is located. There

details of this option a little later on this page.

Press the second button to be sure that the relative option is activated. (It's very important for this demo

Make a block out of the A1 to C1 cells.

Press the Fill button to change the cell's background color to the color of your choice.

Press the first button of the macro toolbar to stop the macro from recording.

OR From the Tools menu, select the Macro and Stop recording options.

The new macro command is now complete. It could have had a lot more instructions than this example. B

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 40/75

only to demonstrate what a macro can do. It's time to see if you may repeat it.

Place the cursor in the A3 cell.

Press the Ctrl and A keys to activate the shortcut to the macro.

Here is the result of the macro. The cells of the third row have now the same background color as the onfor the cells of the first row.

There is an explanation if it didn't work. You forgot to activate the relative position option when asked. Erepeat the macro at the same location instead of beginning it where the cursor is located. It's as for that re

was asked to you to move the cursor in the A3 cell and to activate the relative button.

Because the relative reference option was activated, you may execute the macro to another place rather th

was created. You just need to put the cursor where you need to activate the macro. If the relative option i

activated, the macro will always repeat itself at the same location.

It can be practical for your needs. It depends on the box. You decide when you should activate the relativ

option or not. It's practical when you know that you'll want to apply the macro to another place in your filast exercise, it was necessary to be able to apply it to the A3 to C3 cells.

A 1004 error message can also appear. Generally, it's because you forgot to stop the macro command froThe macro is then caught in an endless loop. The macro is recalled before it's even finished! It will be ne

change the macro.

Change a macro command

From the Tools menu, select the Macro optionSelect the macro of your choice and press the Edit button.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 41/75

 

The Visual BASIC editor will appear with the code of the macro command that you want to change.

The macro indicates that three cells were selected (A1 to C1). It then indicates the color as well as the pa

 background of the selected cells.

Print a macro command

It's possible to print the code while changeing the macro command.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 42/75

From the File menu, select the Print option.

To return to Excel... 

From the File menu, select the Close and return to Microsoft Excel option.

Attach a macro command to a button

It's sometimes very interesting to be able to execute macro commands by just pressing a button; even mo

leave your file to another person. They probably don't know all the macro commands that you created to

The next exercise consists in attaching a macro command to a button.

IMPORTANT: You must already have created a macro that you will need before attaching it to a button

From the Edit menu, select the Toolbar option.

From the list of the available toolbars, select the Forms toolbar.

This toolbar offers you several objects, or controls, that you can place on forms. For the moment, you onworry about the button to attach a macro command.

Press the button.

Move the toolbar if it's necessary.

Place the cursor on the titles bar of the toolbar (the blue bar on top).

Press the left mouse button and move the toolbar towards the place of your choice.

Once the toolbar is at its new location, release the left mouse button.

This toolbar is used for creating forms in Excel files. It facilitates the use of the model for the

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 43/75

Press the left mouse button and determine the place and size of the button.

When satisfied with the size, release the left mouse button.

Excel will automatically ask you for the name of the macro that you want to attach to the newly created b

Select the macro of your choice.Press the OK button.

While the button is still selected, you can change the text on the button to whatever you need it to be.

Once finished, click outside of the button.

To execute the macro that's now connected to the button. 

Place the cursor in the A5 cell.Place the cursor over the button.

Press the left mouse button.

The button now executes the macro. You can apply any macro that you make to a button. It's that easy!

If you wish to change the options of the button. 

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 44/75

Place the cursor over the button.

Press the right mouse button.

A context menu will appear next to the button.

If you want to affect the presentation of this macro button, select the Format Control option.

The properties window of the button will allow you to change all the options of your choice. All the poss

you will be found under these seven tabs: Font, Alignment, Size, Protection, Properties, Margins and We

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 45/75

Under the Font tab you will find all the options for the presentation of the text on the button. You can ch

font, font style, size, color and effects.

The Alignment tab allows you to change the placement of the text inside the button including its' orienta

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 46/75

 

The Size tab allows you to determine exactly the size of the button on the worksheet.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 47/75

 

Like for the protection for cells, it's also possible to protect buttons under the Protection tab. By default, buttons are protected when the protection is activated. You should leave it protected unless you want the

able change the button properties for some reason.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 48/75

 

The Properties tab allows you to decide if the button should change size and placement when you changchange you size and placement of the cells of the worksheet below it. You can also decide to move or no

if you insert or delete rows and columns. By default, the button will not be printed unless you activate th

object option.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 49/75

 

The Margins tab allows you to control the margin, or the space between the text on the button and its bocan use the predetermined margins or change them to your choice.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 50/75

 

You can always save this worksheet as a Web page. So Excel offers you some Web properties under the For buttons, it only allows you to put some alternate

Assign a macro to a drawingIt's interesting, even practical, to place a macro on a command button. It's easier for the users to use the o

you prepared them for them. But these buttons lack originality. They're grey! That's why Excel also offer

 possibility of placing a macro on a drawing. With a bit of work, these drawings can have very interestingare some examples.

Before being able to attach a macro to a drawing, you need two things: a drawing and a macro. Let's pres

you already have both. The next part consists only in attaching a macro to a drawing.

Place the cursor over the drawing.

Press the right mouse button.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 51/75

From the context menu, select the Assign macro option.

From the list of macro commands that you have already prepared, select the one of your choice.

Press the OK button.

If you can't select the Assign macro option, click on the border of the drawing instead of the text inside it

should then be able to assign the macro of your choice. You can repeat this operation on as many drawinwant. It certainly puts a little fun in your file!

Assign a macro to a toolbar

Assigning a button to a toolbar can be done in two

Create a new toolbar 

From the View menu, select the options Toolbar and Customize.

Press the New button.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 52/75

Enter the name you wish to give to your new toolbar and press the OK button.

An empty toolbar will appear on the screen. You can now drag any button that you wish to that toolbar; i

macros.

Creating a button for the toolbar

 Now is the time to add buttons that you will be able to place on any toolbar. You just create a new toolba

 buttons in it. This next step will show you how to add buttons to it, or to any toolbar.

Select the Commands tab.

From the Categories group, select Macros.Drag the Custom Button to your new Toolbar.

The result is that you now have a button on your toolbar. You can drag other button onto it.

Close the Customize toolbar window.

The only thing left to do is to assign a macro to that new button.

Place the cursor over the button.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 53/75

Press the right mouse button.

From the content menu, select the Assign Macro option.

From the list of available macros, select the one you wish to assign to the button.Press the OK button.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 54/75

Let's see if it works.

Place the cursor in the A7 cell.

Press on the button from the new toolbar.

Change button picture

You can now make macros, apply them where you want them and even create toolbars! But it's not over.

 button picture was placed on the toolbar when you added a macro command to it. Excel offers you a list you can use to better represent what your macro command will do.

Place the pointer over the new toolbar button.

Press the right mouse button.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 55/75

 

From the context menu, select the Change Button Image option.

A list of pictures will appear. Select the picture that best represents the action from your macro.

The picture will be replaced. You can change again if you wish.

Edit button picture

The number of pictures you can select from is limited and may not answer your needs. So you can chang pictures or create your own.

Place the pointer over the new toolbar button.Press the right mouse button.

From the context menu, select the Edit Button Image option.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 56/75

 

The size of the picture and the number of colors is limited but not your imagination. You can try any formshade on it, anything you can think!

Once you created the picture you wish, press the OK button.

You can now create you own macros and toolbars. This will help you personalize Excel to better answer

make you more efficient. That's what this site is all about!

Webanalytics provided by

This site is hosted by 1&1.com 

Introduction

A macro command is a series of instructions that are always executed one after the other in the same ordvery practical to automate repetitive tasks. The exercise that follows will demonstrate how to create a macommand. The next macro basically changes the background color of the selected cells. It contains only

command. But after you've finished, you will be able create your own "macros" and insert as many instru

you need.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 57/75

Creating of a macro command

Write the following numbers in the appropriate cells.Place the cursor in the A1 cell.

You must place the cursor in that cell before you can begin your "macro". You'll see why later on.

From the Tools menu, select the Macro option.Select the Record New macro option.

A new window will open asking you for some information about the new macro. The first box asks you f

that you give to this macro. You can also put a letter or a number in the shortcut box. You'll be able to ex

macro by pressing the Ctrl and a keys. You can place in any letter or number that you want. The shortcu

compulsory.

The window asks you if you want to store the macro in this file or in another worksheet file. It's possible

the macro commands in a personal macro file. The same macro can then be used for several files. But thi

those that are really serious about using macros.

For the exercise:

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 58/75

Give a name to your macro. It should represent the actions that will be done such as " Printing_the_budg

name of the macro cannot have any spaces. An underline can be used to link words. It's also possible to h

shortcut key to activate a macro command. This avoids you having to go into the Tools menu, followed b

Macro, Macro commands, select the macro of your choice and pressing on the Execute button.

Enter the data as shown in the picture above.Press the OK button.

All the actions that you go to make will be added to the macro command until you stop the recording.

As soon as you press the OK button, the window disappears and a small toolbar appears in its place. Thi

toolbar has only two buttons. The first one is to stop the macro from recording. The second is to activate

deactivate the relative reference option. This can be important according to the type of macro that you wout. You do not activate this option if you want the macro to do whatever you want it to do at always the

location. You activate this option if you want the macro to start where the active cursor is located. There

details of this option a little later on this page.

Press the second button to be sure that the relative option is activated. (It's very important for this demo

Make a block out of the A1 to C1 cells.

Press the Fill button to change the cell's background color to the color of your choice.

Press the first button of the macro toolbar to stop the macro from recording.

OR From the Tools menu, select the Macro and Stop recording options.

The new macro command is now complete. It could have had a lot more instructions than this example. B

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 59/75

only to demonstrate what a macro can do. It's time to see if you may repeat it.

Place the cursor in the A3 cell.

Press the Ctrl and A keys to activate the shortcut to the macro.

Here is the result of the macro. The cells of the third row have now the same background color as the onefor the cells of the first row.

There is an explanation if it didn't work. You forgot to activate the relative position option when asked. Erepeat the macro at the same location instead of beginning it where the cursor is located. It's as for that re

was asked to you to move the cursor in the A3 cell and to activate the relative button.

Because the relative reference option was activated, you may execute the macro to another place rather th

was created. You just need to put the cursor where you need to activate the macro. If the relative option i

activated, the macro will always repeat itself at the same location.

It can be practical for your needs. It depends on the box. You decide when you should activate the relativ

option or not. It's practical when you know that you'll want to apply the macro to another place in your filast exercise, it was necessary to be able to apply it to the A3 to C3 cells.

A 1004 error message can also appear. Generally, it's because you forgot to stop the macro command froThe macro is then caught in an endless loop. The macro is recalled before it's even finished! It will be ne

change the macro.

Change a macro command

From the Tools menu, select the Macro optionSelect the macro of your choice and press the Edit button.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 60/75

 

The Visual BASIC editor will appear with the code of the macro command that you want to change.

The macro indicates that three cells were selected (A1 to C1). It then indicates the color as well as the pa

 background of the selected cells.

Print a macro command

It's possible to print the code while changeing the macro command.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 61/75

From the File menu, select the Print option.

To return to Excel... 

From the File menu, select the Close and return to Microsoft Excel option.

Attach a macro command to a button

It's sometimes very interesting to be able to execute macro commands by just pressing a button; even mo

leave your file to another person. They probably don't know all the macro commands that you created to

The next exercise consists in attaching a macro command to a button.

IMPORTANT: You must already have created a macro that you will need before attaching it to a button

From the Edit menu, select the Toolbar option.

From the list of the available toolbars, select the Forms toolbar.

This toolbar offers you several objects, or controls, that you can place on forms. For the moment, you onworry about the button to attach a macro command.

Press the button.

Move the toolbar if it's necessary.

Place the cursor on the titles bar of the toolbar (the blue bar on top).

Press the left mouse button and move the toolbar towards the place of your choice.

Once the toolbar is at its new location, release the left mouse button.

This toolbar is used for creating forms in Excel files. It facilitates the use of the model for the

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 62/75

Press the left mouse button and determine the place and size of the button.

When satisfied with the size, release the left mouse button.

Excel will automatically ask you for the name of the macro that you want to attach to the newly created b

Select the macro of your choice.Press the OK button.

While the button is still selected, you can change the text on the button to whatever you need it to be.

Once finished, click outside of the button.

To execute the macro that's now connected to the button. 

Place the cursor in the A5 cell.Place the cursor over the button.

Press the left mouse button.

The button now executes the macro. You can apply any macro that you make to a button. It's that easy!

If you wish to change the options of the button. 

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 63/75

Place the cursor over the button.

Press the right mouse button.

A context menu will appear next to the button.

If you want to affect the presentation of this macro button, select the Format Control option.

The properties window of the button will allow you to change all the options of your choice. All the poss

you will be found under these seven tabs: Font, Alignment, Size, Protection, Properties, Margins and We

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 64/75

Under the Font tab you will find all the options for the presentation of the text on the button. You can ch

font, font style, size, color and effects.

The Alignment tab allows you to change the placement of the text inside the button including its' orienta

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 65/75

 

The Size tab allows you to determine exactly the size of the button on the worksheet.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 66/75

 

Like for the protection for cells, it's also possible to protect buttons under the Protection tab. By default, buttons are protected when the protection is activated. You should leave it protected unless you want the

able change the button properties for some reason.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 67/75

 

The Properties tab allows you to decide if the button should change size and placement when you changchange you size and placement of the cells of the worksheet below it. You can also decide to move or no

if you insert or delete rows and columns. By default, the button will not be printed unless you activate th

object option.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 68/75

 

The Margins tab allows you to control the margin, or the space between the text on the button and its bocan use the predetermined margins or change them to your choice.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 69/75

 

You can always save this worksheet as a Web page. So Excel offers you some Web properties under the For buttons, it only allows you to put some alternate

Assign a macro to a drawingIt's interesting, even practical, to place a macro on a command button. It's easier for the users to use the o

you prepared them for them. But these buttons lack originality. They're grey! That's why Excel also offer

 possibility of placing a macro on a drawing. With a bit of work, these drawings can have very interestingare some examples.

Before being able to attach a macro to a drawing, you need two things: a drawing and a macro. Let's pres

you already have both. The next part consists only in attaching a macro to a drawing.

Place the cursor over the drawing.

Press the right mouse button.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 70/75

From the context menu, select the Assign macro option.

From the list of macro commands that you have already prepared, select the one of your choice.

Press the OK button.

If you can't select the Assign macro option, click on the border of the drawing instead of the text inside i

should then be able to assign the macro of your choice. You can repeat this operation on as many drawinwant. It certainly puts a little fun in your file!

Assign a macro to a toolbar

Assigning a button to a toolbar can be done in two

Create a new toolbar 

From the View menu, select the options Toolbar and Customize.

Press the New button.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 71/75

Enter the name you wish to give to your new toolbar and press the OK button.

An empty toolbar will appear on the screen. You can now drag any button that you wish to that toolbar; i

macros.

Creating a button for the toolbar

 Now is the time to add buttons that you will be able to place on any toolbar. You just create a new toolba

 buttons in it. This next step will show you how to add buttons to it, or to any toolbar.

Select the Commands tab.

From the Categories group, select Macros.Drag the Custom Button to your new Toolbar.

The result is that you now have a button on your toolbar. You can drag other button onto it.

Close the Customize toolbar window.

The only thing left to do is to assign a macro to that new button.

Place the cursor over the button.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 72/75

Press the right mouse button.

From the content menu, select the Assign Macro option.

From the list of available macros, select the one you wish to assign to the button.Press the OK button.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 73/75

Let's see if it works.

Place the cursor in the A7 cell.

Press on the button from the new toolbar.

Change button picture

You can now make macros, apply them where you want them and even create toolbars! But it's not over.

 button picture was placed on the toolbar when you added a macro command to it. Excel offers you a list you can use to better represent what your macro command will do.

Place the pointer over the new toolbar button.

Press the right mouse button.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 74/75

 

From the context menu, select the Change Button Image option.

A list of pictures will appear. Select the picture that best represents the action from your macro.

The picture will be replaced. You can change again if you wish.

Edit button picture

The number of pictures you can select from is limited and may not answer your needs. So you can chang pictures or create your own.

Place the pointer over the new toolbar button.Press the right mouse button.

From the context menu, select the Edit Button Image option.

7/28/2019 Attach a Macro Command to a Button

http://slidepdf.com/reader/full/attach-a-macro-command-to-a-button 75/75

 

The size of the picture and the number of colors is limited but not your imagination. You can try any formshade on it, anything you can think!

Once you created the picture you wish, press the OK button.

You can now create you own macros and toolbars. This will help you personalize Excel to better answer

make you more efficient. That's what this site is all about!


Recommended