1. คลิกขวา ที่ ribbon และเลือก Customize the Ribbon.
![Customize the Ribbon in Excel Customize the Ribbon in Excel](http://www.excel-easy.com/vba/images/create-a-macro/customize-ribbon.png)
2.เลือก Customize the Ribbon, บนแทบด้านขวาให้เลือก ถูก Developer
![Turn on the Developer Tab Turn on the Developer Tab](http://www.excel-easy.com/vba/images/create-a-macro/turn-on-developer-tab.png)
3. คลิก OK
4.จะเห็นแทบ Develper ขึ้น
Command Button
![Developer Tab Developer Tab](http://www.excel-easy.com/vba/images/create-a-macro/developer-tab.png)
![Turn on the Developer Tab Turn on the Developer Tab](http://www.excel-easy.com/vba/images/create-a-macro/turn-on-developer-tab.png)
3. คลิก OK
4.จะเห็นแทบ Develper ขึ้น
Command Button
![Developer Tab Developer Tab](http://www.excel-easy.com/vba/images/create-a-macro/developer-tab.png)
.
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.
![Insert a command button control Insert a command button control](http://www.excel-easy.com/vba/images/create-a-macro/insert-command-button-control.png)
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.
![View Code View Code](http://www.excel-easy.com/vba/images/create-a-macro/view-code.png)
The Visual Basic Editor appears.
3. Place your cursor between Private Sub CommandButton1_Click() and End Sub.
4. Add the code line shown below.
![Visual Basic Editor Visual Basic Editor](http://www.excel-easy.com/vba/images/create-a-macro/visual-basic-editor.png)
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:
![Excel Macro Result Excel Macro Result](http://www.excel-easy.com/vba/images/create-a-macro/macro-result.png)
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.
![Open the Visual Basic Editor Open the Visual Basic Editor](http://www.excel-easy.com/vba/images/create-a-macro/open-visual-basic-editor.png)
The Visual Basic Editor appears.
![Visual Basic Editor Visual Basic Editor](http://www.excel-easy.com/vba/images/create-a-macro/visual-basic-editor.png)
ไม่มีความคิดเห็น:
แสดงความคิดเห็น