PC Review


Reply
Thread Tools Rate Thread

Copy a command button

 
 
a m spock
Guest
Posts: n/a
 
      31st May 2009
On a worksheet I have command buttons to activate sheet specific macros. How
do I copy them to other sheets in the same workbook to perform the same task
for that sheet. Currently I use ctrl x to activate the macros.
 
Reply With Quote
 
 
 
 
OssieMac
Guest
Posts: n/a
 
      31st May 2009
When you say Sheet specific macros I assume that you mean the command buttons
are ActiveX controls either from the Controls Toolbox toolbar in pre xl2007
versions or from the ActiveX buttons in xl2007. If so then you can place the
main part of the code in a standard module and call the code from the command
button code.

Example;
In the standard module insert code as
Sub MyMacroCode()

'your code here

End Sub

the button code for each sheet would be like this:
Private Sub CommandButton1_Click()
Call MyMacroCode
End Sub

The code in the standard module needs to specifically address the worksheet
that it is intended to process. If selecting the sheets then ActiveSheet can
be used otherwise you can use a parameter in the calling code like this

Call MyMacroCode(Activesheet.Name)

and the sub in the standard module would be like this
Sub MyMacroCode(strShtName)
You then use strShtName in lieu of the actual sheet name in your code like
this.

Sheets("Sheet1").Range("A1")
becomes this
Sheets(strMyShtName).Range("A1")

Note no quotes around the variable strMyShtName.

Another option to the above is to use a Forms button (from the Forms toolbar
in pre xl2007 or from the forms controls in xl2007) and place the code in a
standard module and you can copy that button to all sheets and the button
always calls the same code. I personally don't like the method but I guess
not everyone would agree with me.


--
Regards,

OssieMac


"a m spock" wrote:

> On a worksheet I have command buttons to activate sheet specific macros. How
> do I copy them to other sheets in the same workbook to perform the same task
> for that sheet. Currently I use ctrl x to activate the macros.

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Command Button to Copy Data Pamela Microsoft Access Forms 1 30th Dec 2009 04:00 PM
add a command button and when i click on the button it will copy =?Utf-8?B?cm9uYWJyaW9uZXM=?= Microsoft Word Document Management 2 22nd Jun 2006 07:38 PM
add a command button and when i click on the button it will copy =?Utf-8?B?cm9uYWJyaW9uZXM=?= Microsoft Word Document Management 0 22nd Jun 2006 06:33 PM
Command button copy array Noslien Microsoft Excel Programming 2 19th Feb 2006 10:04 PM
Copy down command button sowetoddid Microsoft Excel Programming 1 16th Jun 2004 03:48 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:59 AM.