Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
command button code dummy Excel Discussion (Misc queries) 2 December 1st 09 02:57 PM
VBA code behind command button [email protected] Excel Worksheet Functions 1 March 22nd 06 08:13 PM
Command Button VBA code Dave Peterson Excel Discussion (Misc queries) 2 January 25th 05 11:28 PM
Adding a command button Roy Thompson Excel Programming 2 October 4th 04 10:12 PM
Dynamically Adding Code to Buttons on an existing UserForm Peter Street Excel Programming 2 September 29th 03 09:54 AM


All times are GMT +1. The time now is 03:27 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"