Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Can't call a subroutine

Excel 2003

The following works within my code:-
Call CommandButton10_Click
where CB10 is one of many on a Userform
and CommandButton10_Click is a subroutine "on" the Userform.

The problem comes when I try to make the CommandButton10 part a variable.
My code will produce a value for the variable "MyCommandButton" which might
be CommandButton15 for example.
Then I try to make the call as follows:-
Call MyCommandButton(&"_Click")
a compile error "Expected Sub, Function or Property" results.

Is this just my bad syntax, or am I trying to do something which VBA doesn't
like?
donwb


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Can't call a subroutine

I don't know of a facility in VBA that will allow you to execute the click
event by code. But I am not the ripest banana in the bunch.

"donwb" wrote:

Excel 2003

The following works within my code:-
Call CommandButton10_Click
where CB10 is one of many on a Userform
and CommandButton10_Click is a subroutine "on" the Userform.

The problem comes when I try to make the CommandButton10 part a variable.
My code will produce a value for the variable "MyCommandButton" which might
be CommandButton15 for example.
Then I try to make the call as follows:-
Call MyCommandButton(&"_Click")
a compile error "Expected Sub, Function or Property" results.

Is this just my bad syntax, or am I trying to do something which VBA doesn't
like?
donwb



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default Can't call a subroutine

Try at

Application.Run MyCommandButton & "_Click"

Tim

"donwb" wrote in message
...
Excel 2003

The following works within my code:-
Call CommandButton10_Click
where CB10 is one of many on a Userform
and CommandButton10_Click is a subroutine "on" the Userform.

The problem comes when I try to make the CommandButton10 part a variable.
My code will produce a value for the variable "MyCommandButton" which
might be CommandButton15 for example.
Then I try to make the call as follows:-
Call MyCommandButton(&"_Click")
a compile error "Expected Sub, Function or Property" results.

Is this just my bad syntax, or am I trying to do something which VBA
doesn't like?
donwb



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Can't call a subroutine

the easiest way to overcome these problems is to insert a module and place
the required code within a sub in the module like this

Sub CommandButton1_Click_Routine()
MsgBox "this sub called from command button1"
End Sub

then in the event code you call the sub in the module like this

Private Sub CommandButton1_Click()
Call CommandButton1_Click_Routine
End Sub


You can then call the sub in the module from any other event routine and you
don't have to try to call the actual event.


--
Regards,

OssieMac


"Tim Williams" wrote:

Try at

Application.Run MyCommandButton & "_Click"

Tim

"donwb" wrote in message
...
Excel 2003

The following works within my code:-
Call CommandButton10_Click
where CB10 is one of many on a Userform
and CommandButton10_Click is a subroutine "on" the Userform.

The problem comes when I try to make the CommandButton10 part a variable.
My code will produce a value for the variable "MyCommandButton" which
might be CommandButton15 for example.
Then I try to make the call as follows:-
Call MyCommandButton(&"_Click")
a compile error "Expected Sub, Function or Property" results.

Is this just my bad syntax, or am I trying to do something which VBA
doesn't like?
donwb




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
Call a subroutine using variable subroutine name dhstein Excel Discussion (Misc queries) 3 July 26th 09 08:28 PM
How To Quit Subroutine from a called subroutine Rich J[_2_] Excel Programming 5 February 20th 07 06:48 PM
Call subroutine from another workbook DejaVu[_55_] Excel Programming 2 November 3rd 05 04:12 PM
Call Subx for excel 97 Add-In subroutine Dave D-C[_3_] Excel Programming 4 March 2nd 05 08:05 PM
Subroutine call without file reference jaf Excel Programming 0 August 25th 03 05:52 PM


All times are GMT +1. The time now is 01:58 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"