Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Unable to call Command Button's Click() method from a differen

Zach,

While this will work just fine, my preference is to not call one event
handler from another. Instead I would create a class or a module, put the
common code in a helper method that gets called from both event handlers.
The reason for this is that if for some reason you change or remove Button1
then Button2 will be ignorant since it's now decoupled from Button1.

for Example:

Sub Button1_Click()
Call HelperMethod()
End Sub

Sub Button2_Click()
Call HelperMethod()
End Sub

Sub HelperMethod()
' Put your common code here.
End Sub

- Al

"Jim Thomlinson" wrote:

You need to fully declare where the command button lives otherwise how would
the program know where to look. You could have the same command button on 2
or more sheets... Give this a try.

Call Sheet1.Command1_Click()
or
Call Sheets("My Sheet").Command1_Click()

You are correct that the procedure needs to be public so leave that as it is.
--
HTH...

Jim Thomlinson


" wrote:

Hi all-

I have a command button on Sheet1, with a Command1_Click() method. I
want to call that procedure from the Command2_Click() method which is
on Sheet2. Even with both procedures defined as Public, I am unable
to get this to work. I have tried

Call Command1_Click()
Call Command1.click

I get "Sub or function not defined" for Command1_Click() & "Object
Required" for Command1.click.

Any thoughts?

Thank you in advance!

Zacah


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
Unable to click on charts & unable to create any new charts Excel Snapclick Charts and Charting in Excel 4 February 1st 09 07:59 PM
GetObject method not work after Call Shell Method ben Excel Programming 8 February 21st 06 03:45 PM
Unable to call external program/dll pipo Excel Programming 1 May 30th 05 08:11 AM
How do I call a method in VB from Excel with JUST code? Doseeson Excel Programming 2 May 28th 05 12:26 AM
How do I call a method in VB from Excel with JUST code? K Dales[_2_] Excel Programming 0 May 27th 05 09:57 PM


All times are GMT +1. The time now is 10:39 AM.

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

About Us

"It's about Microsoft Excel"