Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Calling sub from CommandButton knowing which sheet is active

I have many sheets with a command button on it using the same code.
I want to change this so I have one code.

I put that code in a module and made it PUBLIC

Public Sub Process()
' do stuff
client = Me.Range("C4")
' do stuf
end sub


my Command button on each sheet now had this code:
Private Sub CommandButton2_Click()
Call process
end sub


The problem I have is at the "ME" statement gives me an error -
"Invalid use of ME keyword"
The subroutine takes inforrmation from the sheet with the command
button and puts it on a different sheet. How do I code so the sheet
the code is called from is the active sheet or it knows its the active
sheet?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Calling sub from CommandButton knowing which sheet is active

Hi G,

Try something like:

'=============
Private Sub CommandButton2_Click()
Call Process(Me)
End Sub

Public Sub Process(SH As Worksheet)
' do stuff
client = SH.Range("C4").Value
' do stuf
End Sub
'<<=============


---
Regards,
Norman




"gtslabs" wrote in message
ps.com...
I have many sheets with a command button on it using the same code.
I want to change this so I have one code.

I put that code in a module and made it PUBLIC

Public Sub Process()
' do stuff
client = Me.Range("C4")
' do stuf
end sub


my Command button on each sheet now had this code:
Private Sub CommandButton2_Click()
Call process
end sub


The problem I have is at the "ME" statement gives me an error -
"Invalid use of ME keyword"
The subroutine takes inforrmation from the sheet with the command
button and puts it on a different sheet. How do I code so the sheet
the code is called from is the active sheet or it knows its the active
sheet?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Calling sub from CommandButton knowing which sheet is active

Thanks Norman that worked.

How can I access that SUB from each of the 50 sheets I already have
made before I implemented this new code?

I tried copying the Command button to another sheet but it left the
code blank.
I also tried putting it in the Macro list to call it from each sheet
but the "Me" gave me and error also.

I remember vaugly that I if I select multiple sheets I can somehow
loop thru them all.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Calling sub from CommandButton knowing which sheet is active

Hi G,

'-------------------
How can I access that SUB from each of the 50 sheets I already have
made before I implemented this new code?

I tried copying the Command button to another sheet but it left the
code blank.
I also tried putting it in the Macro list to call it from each sheet
but the "Me" gave me and error also.

I remember vaugly that I if I select multiple sheets I can somehow
loop thru them all.
'-------------------

Rather than inserting a new CommandButton on 50+
sheets, why not insert a new button on a toolbar and
assign the required the requred macro to the toolbar
button. In this way, you could use the ActiveSheet
property to identify the sheet.


---
Regards,
Norman


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
Knowing the creation date of an excel sheet email attachment Alice Excel Discussion (Misc queries) 3 September 23rd 08 05:37 PM
Copy from active sheet and paste into new sheet using info from cell in active Ingve Excel Programming 3 January 23rd 06 09:57 PM
How save active workbook w/o knowing name John Excel Programming 3 January 20th 06 12:16 AM
Referencing an External Sheet without Knowing its Name - XL2K [email protected] Excel Programming 8 November 15th 05 01:32 PM
Need an EXPERT in VBA and knowing how to manipulate objects on an excel sheet holysoul Excel Programming 2 May 11th 04 01:20 PM


All times are GMT +1. The time now is 05:32 PM.

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"