Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Adding Code to an Existing Command Button with VBA
My Excel file has two sheets. The first sheet (we will call this sheet1) has one command button, and the second sheet (we will call this sheet2) has two command buttons. If the command button on sheet1 is clicked, it will copy the entire sheet2 to a new sheet (sheet3). Now, since the sheet has been copied to a new sheet, the command buttons in sheet3 lose their code. For example, here is the new code for one of the command buttons in sheet3: -Private Sub CommandButton2_Click() End Sub- Now what I would like to do is insert some code into this new command button in sheet3 via the command button code from sheet1 that I originally used to copy sheet2 to sheet3. The code I would like to insert is as follows: -Application.DisplayAlerts = False Sheets("sheet1").Visible = True Sheets("sheet1").Select Sheets("sheet3").delete Application.DisplayAlerts = True- My problem is I do not know how to do this in VBA. Can someone help me out? Thanks! -- jasoncw ------------------------------------------------------------------------ jasoncw's Profile: http://www.excelforum.com/member.php...o&userid=17853 View this thread: http://www.excelforum.com/showthread...hreadid=345555 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Adding Code to an Existing Command Button with VBA
see chip pearson's page on working on code with code
http://www.cpearson.com/excel/vbe.htm -- Regards, Tom Ogilvy "jasoncw" wrote in message ... My Excel file has two sheets. The first sheet (we will call this sheet1) has one command button, and the second sheet (we will call this sheet2) has two command buttons. If the command button on sheet1 is clicked, it will copy the entire sheet2 to a new sheet (sheet3). Now, since the sheet has been copied to a new sheet, the command buttons in sheet3 lose their code. For example, here is the new code for one of the command buttons in sheet3: -Private Sub CommandButton2_Click() End Sub- Now what I would like to do is insert some code into this new command button in sheet3 via the command button code from sheet1 that I originally used to copy sheet2 to sheet3. The code I would like to insert is as follows: -Application.DisplayAlerts = False Sheets("sheet1").Visible = True Sheets("sheet1").Select Sheets("sheet3").delete Application.DisplayAlerts = True- My problem is I do not know how to do this in VBA. Can someone help me out? Thanks! -- jasoncw ------------------------------------------------------------------------ jasoncw's Profile: http://www.excelforum.com/member.php...o&userid=17853 View this thread: http://www.excelforum.com/showthread...hreadid=345555 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
command button code | Excel Discussion (Misc queries) | |||
VBA code behind command button | Excel Worksheet Functions | |||
Command Button VBA code | Excel Discussion (Misc queries) | |||
Adding a command button | Excel Programming | |||
Dynamically Adding Code to Buttons on an existing UserForm | Excel Programming |