Sie sind auf Seite 1von 30

Developer Tab

To turn on the Developter tab, execute the following steps.


1. Right click anywhere on the ribbon, and then click Customize the Ribbon.

2. Under Customize the Ribbon, on the right side of the dialog box, select Main tabs (if necessary).
3. Check the Developer check box.

4. Click OK.
5. You can find the Developer tab next to the View tab.

Command Button
To place a command button on your worksheet, execute the following steps.
1. On the Developer tab, click Insert.
2. In the ActiveX Controls group, click Command Button.

3. Drag a command button on your worksheet.

Assign a Macro
To assign a macro (one or more code lines) to the command button, execute the following steps.
1. Right click CommandButton1 (make sure Design Mode is selected).
2. Click View Code.

The Visual Basic Editor appears.


3. Place your cursor between Private Sub CommandButton1_Click() and End Sub.
4. Add the code line shown below.

Note: the window on the left with the names Sheet1, Sheet2 and Sheet3 is called the Project Explorer.
If the Project Explorer is not visible, click View, Project Explorer. To add the Code window for the first
sheet, click Sheet1 (Sheet1).
5. Close the Visual Basic Editor.
6. Click the command button on the sheet (make sure Design Mode is deselected).
Result:

Congratulations. You've just created a macro in Excel!

Visual Basic Editor


To open the Visual Basic Editor, on the Developer tab, click Visual Basic.

The Visual Basic Editor appears.

NEW ONE

Method 1
Excel 2007 and 2010

1. 1
Click the Developer tab on the Ribbon at the top of the screen. If
the tab is not showing up on your screen, you can add it as follows:

For Excel 2010: click the File Tab then select options. On the left
hand side of the Excel options dialog box, click Customize Ribbon.
Then, on the right hand side box select Developer.

<img alt="Image titled Write a Simple Macro in Microsoft Excel Step


1Bullet1" src="http://pad1.whstatic.com/images/thumb/2/2d/Writea-Simple-Macro-in-Microsoft-Excel-Step-1Bullet1.jpg/aid229922728px-Write-a-Simple-Macro-in-Microsoft-Excel-Step-1Bullet1.jpg"
width="728" height="546" class="whcdn">
o

For Excel 2007: click the Microsoft Office button, then Excel Options.
In the Popular category, under Top Options for Working with Excel,
select Show Developer Tab in Ribbon.

<img alt="Image titled Write a Simple Macro in Microsoft Excel Step


1Bullet2" src="http://pad2.whstatic.com/images/thumb/e/e1/Writea-Simple-Macro-in-Microsoft-Excel-Step-1Bullet2.jpg/aid229922728px-Write-a-Simple-Macro-in-Microsoft-Excel-Step-1Bullet2.jpg"
width="728" height="546" class="whcdn">

<img alt="Image titled Write a Simple Macro in Microsoft Excel Step 2"
src="http://pad1.whstatic.com/images/thumb/4/4c/Write-a-Simple-Macroin-Microsoft-Excel-Step-2.jpg/aid229922-728px-Write-a-Simple-Macro-inMicrosoft-Excel-Step-2.jpg" width="728" height="546" class="whcdn">

2
Change the security settings. In Trust Centre, Under Macro Settings,
click Enable All Macros, then click OK.

Note that this security setting is not ideal for basic use. When
you've finished creating your macro, go back and un-click Enable All
Macros.

<img alt="Image titled Write a Simple Macro in Microsoft Excel Step


3" src="http://pad3.whstatic.com/images/thumb/0/07/Write-aSimple-Macro-in-Microsoft-Excel-Step-3.jpg/aid229922-728px-Writea-Simple-Macro-in-Microsoft-Excel-Step-3.jpg" width="728"
height="546" class="whcdn">

3
Click Record Macro. You'll find it on the Developer tab under Code.

<img alt="Image titled Write a Simple Macro in Microsoft Excel Step


4" src="http://pad2.whstatic.com/images/thumb/4/4c/Write-aSimple-Macro-in-Microsoft-Excel-Step-4.jpg/aid229922-728px-Writea-Simple-Macro-in-Microsoft-Excel-Step-4.jpg" width="728"
height="546" class="whcdn">

<a href="http://us-ads.openx.net/w/1.0/rc?
cs=b0a175c203&cb=1459247101607&url=http%3A%2F
%2Fwww.wikihow.com%2FWrite-a-Simple-Macro-in-MicrosoftExcel&c.width=726&c.height=106&c.tag_id=21083&c.taglink_id=38041&
c.scale=1.0027548&c.url=http%3A%2F%2Fwww.wikihow.com%2FWrite-aSimple-Macro-in-Microsoft-

Excel&c.params=&c.impression_type=26&c.placement_id=ad0.15321764
61000796" ><img src="http://us-ads.openx.net/w/1.0/ai?
auid=538214314&cs=b0a175c203&cb=1459247101607&url=http%3A
%2F%2Fwww.wikihow.com%2FWrite-a-Simple-Macro-in-MicrosoftExcel&c.width=726&c.height=106&c.tag_id=21083&c.taglink_id=38041&
c.scale=1.0027548&c.url=http%3A%2F%2Fwww.wikihow.com%2FWrite-aSimple-Macro-in-MicrosoftExcel&c.params=&c.impression_type=26&c.placement_id=ad0.15321764
61000796" border="0" alt=""></a>

4
Name your macro. The first character of the name must be a letter; after
that, you can use characters, numbers and underscores. Macro names
cannot have spaces.

Don't use the same name for your macro as an existing cell
reference.

<img alt="Image titled Write a Simple Macro in Microsoft Excel Step


5" src="http://pad3.whstatic.com/images/thumb/7/7e/Write-aSimple-Macro-in-Microsoft-Excel-Step-5.jpg/aid229922-728px-Writea-Simple-Macro-in-Microsoft-Excel-Step-5.jpg" width="728"
height="546" class="whcdn">

5
Set a shortcut for your macro (optional). Type a letter in the Shortcut
Key box. A lowercase letter will translate to CTRL + letter; an uppercase
letter will be CTRL + SHIFT + letter.

<img alt="Image titled Write a Simple Macro in Microsoft Excel Step


6" src="http://pad1.whstatic.com/images/thumb/4/4d/Write-aSimple-Macro-in-Microsoft-Excel-Step-6.jpg/aid229922-728px-Writea-Simple-Macro-in-Microsoft-Excel-Step-6.jpg" width="728"
height="546" class="whcdn">

6
Choose where to store your macro. In the Store Macro In list, select
the workbook where you want to store the macro. If you want it to be
available whenever you run Excel, select Personal Macro Workbook.

<img alt="Image titled Write a Simple Macro in Microsoft Excel Step


7" src="http://pad1.whstatic.com/images/thumb/6/63/Write-aSimple-Macro-in-Microsoft-Excel-Step-7.jpg/aid229922-728px-Writea-Simple-Macro-in-Microsoft-Excel-Step-7.jpg" width="728"
height="546" class="whcdn">

7
Describe your macro. Write this in the Description box.

<img alt="Image titled Write a Simple Macro in Microsoft Excel Step


8" src="http://pad3.whstatic.com/images/thumb/c/c3/Write-aSimple-Macro-in-Microsoft-Excel-Step-8.jpg/aid229922-728px-Writea-Simple-Macro-in-Microsoft-Excel-Step-8.jpg" width="728"
height="546" class="whcdn">

8
Click OK to start recording your macro.

<img alt="Image titled Write a Simple Macro in Microsoft Excel Step


9" src="http://pad3.whstatic.com/images/thumb/7/70/Write-aSimple-Macro-in-Microsoft-Excel-Step-9.jpg/aid229922-728px-Writea-Simple-Macro-in-Microsoft-Excel-Step-9.jpg" width="728"
height="546" class="whcdn">

9
Perform the actions you want the macro to record.

<img alt="Image titled Write a Simple Macro in Microsoft Excel Step


10" src="http://pad3.whstatic.com/images/thumb/9/91/Write-aSimple-Macro-in-Microsoft-Excel-Step-10.jpg/aid229922-728pxWrite-a-Simple-Macro-in-Microsoft-Excel-Step-10.jpg" width="728"
height="546" class="whcdn">

10
Stop recording. Go to the Developer tab, click Code, then click Stop
Recording.

Method 2
Excel 2003

1. 1
Change the security level. Switch the security level from Medium to
Low.

Click Tools -> Options -> Security.

<img alt="Image titled Write a Simple Macro in Microsoft Excel Step


11Bullet1" src="http://pad1.whstatic.com/images/thumb/8/8d/Writea-Simple-Macro-in-Microsoft-Excel-Step-11Bullet1.jpg/aid229922728px-Write-a-Simple-Macro-in-Microsoft-Excel-Step-11Bullet1.jpg"
width="728" height="546" class="whcdn">
o

Click Macro Security.

<img alt="Image titled Write a Simple Macro in Microsoft Excel Step


11Bullet2" src="http://pad2.whstatic.com/images/thumb/3/3d/Writea-Simple-Macro-in-Microsoft-Excel-Step-11Bullet2.jpg/aid229922728px-Write-a-Simple-Macro-in-Microsoft-Excel-Step-11Bullet2.jpg"
width="728" height="546" class="whcdn">
o

Select Security Level. Select Low.

<img alt="Image titled Write a Simple Macro in Microsoft Excel Step


11Bullet3" src="http://pad3.whstatic.com/images/thumb/6/6d/Writea-Simple-Macro-in-Microsoft-Excel-Step-11Bullet3.jpg/aid229922728px-Write-a-Simple-Macro-in-Microsoft-Excel-Step-11Bullet3.jpg"
width="728" height="546" class="whcdn">

<img alt="Image titled Write a Simple Macro in Microsoft Excel Step


12" src="http://pad2.whstatic.com/images/thumb/7/75/Write-aSimple-Macro-in-Microsoft-Excel-Step-12.jpg/aid229922-728pxWrite-a-Simple-Macro-in-Microsoft-Excel-Step-12.jpg" width="728"
height="546" class="whcdn">

2
Start recording your macro. Navigate to Tools -> Macro -> Record New
Macro.

<img alt="Image titled Write a Simple Macro in Microsoft Excel Step


13" src="http://pad1.whstatic.com/images/thumb/a/ab/Write-aSimple-Macro-in-Microsoft-Excel-Step-13.jpg/aid229922-728pxWrite-a-Simple-Macro-in-Microsoft-Excel-Step-13.jpg" width="728"
height="546" class="whcdn">

3
Name your macro. The character of the name must be a letter; after
that, you can use symbols, numbers or underscores. No spaces are
allowed.

Don't use the same name for your macro as an existing cell
reference.

<img alt="Image titled Write a Simple Macro in Microsoft Excel Step


14" src="http://pad2.whstatic.com/images/thumb/0/07/Write-aSimple-Macro-in-Microsoft-Excel-Step-14.jpg/aid229922-728pxWrite-a-Simple-Macro-in-Microsoft-Excel-Step-14.jpg" width="728"
height="546" class="whcdn">

4
Code a shortcut for your macro (optional). Enter a letter in the
Shortcut Key box. A lowercase letter will make the shortcut CTRL + letter;
uppercase will be CTRL + SHIFT + letter.

<img alt="Image titled Write a Simple Macro in Microsoft Excel Step


15" src="http://pad2.whstatic.com/images/thumb/b/b0/Write-aSimple-Macro-in-Microsoft-Excel-Step-15.jpg/aid229922-728pxWrite-a-Simple-Macro-in-Microsoft-Excel-Step-15.jpg" width="728"
height="546" class="whcdn">

5
Choose where to store your macro. In the Store Macro box, select a
location for your macro. Click Personal Macro Workbook if you want it
to be available whenever you open Excel.

<img alt="Image titled Write a Simple Macro in Microsoft Excel Step


16" src="http://pad2.whstatic.com/images/thumb/2/2d/Write-aSimple-Macro-in-Microsoft-Excel-Step-16.jpg/aid229922-728pxWrite-a-Simple-Macro-in-Microsoft-Excel-Step-16.jpg" width="728"
height="546" class="whcdn">

6
Write a description of your macro.

When you're done, click OK.

<img alt="Image titled Write a Simple Macro in Microsoft Excel Step


16Bullet1" src="http://pad1.whstatic.com/images/thumb/b/ba/Writea-Simple-Macro-in-Microsoft-Excel-Step-16Bullet1.jpg/aid229922728px-Write-a-Simple-Macro-in-Microsoft-Excel-Step-16Bullet1.jpg"
width="728" height="546" class="whcdn">

<img alt="Image titled Write a Simple Macro in Microsoft Excel Step


17" src="http://pad3.whstatic.com/images/thumb/f/f9/Write-aSimple-Macro-in-Microsoft-Excel-Step-17.jpg/aid229922-728pxWrite-a-Simple-Macro-in-Microsoft-Excel-Step-17.jpg" width="728"
height="546" class="whcdn">

7
Record your macro. Remember, Record Macro is still on. Carry out the
actions that you want Excel to record as your macro.

<img alt="Image titled Write a Simple Macro in Microsoft Excel Step


18" src="http://pad1.whstatic.com/images/thumb/c/c3/Write-aSimple-Macro-in-Microsoft-Excel-Step-18.jpg/aid229922-728pxWrite-a-Simple-Macro-in-Microsoft-Excel-Step-18.jpg" width="728"
height="546" class="whcdn">

8
Click Stop Recording. You can find this option on the Stop Recording
toolbar.

Reader Questions and Answers

Unanswered Questions

How do I write an if statement in a data macro?


Answer Flag as bad question Flag as bad question

Show more unanswered questions


Add New Question

Answered Questions
Don't see your question? Ask it here:
Submit

Tips

If you already know the code for your macro, you can enter it in the
Microsoft Visual Basic Editor. In Excel 2007 and 2010, it's located under
the Developer tab, in Code. In Excel 2003, click Tools -> Macro -> Visual
Basic Editor.

You can make your macro behave as one of Microsoft Excel's formula
functions so you can use it inside the spreadsheets to calculate things.
Basically you have to change your "Sub" to a "Function", add parameters
and return a value, but this is explained in its own how-to, look for it in the
related wikiHows section.

Use the Range, Sheet and Workbook objects to interact with the
information in your worksheets. The ActiveWorkbook, ActiveSheet and
Selection objects point to the current book, sheet and range of cells in the
Application.

The forums at ExcelForum are filled with helpful people who will work hard
to answer your politely asked Excel questions.

Warnings

Due to security measures, some people may disable macros. Make sure
you let your colleagues know the book you're sending them has macros
and that they can trust they're not going to damage their computers.

Das könnte Ihnen auch gefallen