PC Review


Reply
Thread Tools Rate Thread

Application.Evaluate

 
 
Carim
Guest
Posts: n/a
 
      7th Jan 2009
Hi,

In a class module, within a Private Sub ButtonGroup_Click() , I cannot
have the
Application.Evaluate to execute itself ...
I am stuck with these two lines :

Back2Top = "CommandButton" & z & "_Click"
Application.Evaluate (Back2Top)

Thanks a lot for your help
and Happy New Year
Cheers
 
Reply With Quote
 
 
 
 
Peter T
Guest
Posts: n/a
 
      7th Jan 2009
What are you trying to evaluate, as written Back2Top is simply a string and
nothing else.

Regards,
Peter T

"Carim" <(E-Mail Removed)> wrote in message
news:c3c80811-53fa-4b12-b83e-(E-Mail Removed)...
> Hi,
>
> In a class module, within a Private Sub ButtonGroup_Click() , I cannot
> have the
> Application.Evaluate to execute itself ...
> I am stuck with these two lines :
>
> Back2Top = "CommandButton" & z & "_Click"
> Application.Evaluate (Back2Top)
>
> Thanks a lot for your help
> and Happy New Year
> Cheers



 
Reply With Quote
 
Carim
Guest
Posts: n/a
 
      7th Jan 2009
Not sure to understand your remark ...
The string is the instruction I would like to have executed ...
How should I use the Application.Evaluate instruction to execute
the Command#_Click() ... ?

Thanks for your help
 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      7th Jan 2009
A string is a string, like "abc", it's not an instruction or a formula. I
suspect you don't mean evaluate. Also a 'Sub' does not return a result like
a function, so what you mentioned in your OP does not make any sense.

If(?) you mean you want to "call" the procedure named Command#_Click() that
exists in a sheet module, try something like this -

sProc = Worksheets("Sheet1").CodeName & ".CommandButton" & i & "_Click"
Application.Run sProc

or
sProc = "CommandButton" & i & "_Click"
CallByName Worksheets("Sheet 1"), sProc, VbMethod

Or if(?) the procedure is in a Userform and you are calling it in a userform
sProc = "CommandButton" & i & "_Click"
CallByName Me, sProc, VbMethod

You will need to change Private to Public before the procedure names in the
sheet/userform module (or simply delete Private).

Regards,
Peter T


"Carim" <(E-Mail Removed)> wrote in message
news:0149ec44-f6da-4a64-9246-(E-Mail Removed)...
> Not sure to understand your remark ...
> The string is the instruction I would like to have executed ...
> How should I use the Application.Evaluate instruction to execute
> the Command#_Click() ... ?
>
> Thanks for your help



 
Reply With Quote
 
Carim
Guest
Posts: n/a
 
      7th Jan 2009
On Jan 7, 6:28*pm, "Peter T" <peter_t@discussions> wrote:
> A string is a string, like "abc", it's not an instruction or a formula. I
> suspect you don't mean evaluate. Also a 'Sub' does not return a result like
> a function, so what you mentioned in your OP does not make any sense.
>
> If(?) you mean you want to "call" the procedure named Command#_Click() that
> exists in a sheet module, try something like this -
>
> sProc = Worksheets("Sheet1").CodeName & ".CommandButton" & i & "_Click"
> Application.Run sProc
>
> or
> sProc = "CommandButton" & i & "_Click"
> CallByName Worksheets("Sheet 1"), sProc, VbMethod
>
> Or if(?) the procedure is in a Userform and you are calling it in a userform
> sProc = "CommandButton" & i & "_Click"
> CallByName Me, sProc, VbMethod
>
> You will need to change Private to Public before the procedure names in the
> sheet/userform module (or simply delete Private).
>
> Regards,
> Peter T
>
> "Carim" <carim...@yahoo.com> wrote in message
>
> news:0149ec44-f6da-4a64-9246-(E-Mail Removed)...
>
>
>
> > Not sure to understand your remark ...
> > The string is the instruction I would like to have executed ...
> > How should I use the Application.Evaluate instruction to execute
> > the Command#_Click() ... ?

>
> > Thanks for your help- Hide quoted text -

>
> - Show quoted text -


Peter,

Thanks a lot ... You are absolutely right ...
And you have just opened my eyes ... !!!
I 'm gonna rush to this section to implement your recommendation...
Best Regards ... and Best Wishes for the new year ...
Carim
 
Reply With Quote
 
Carim
Guest
Posts: n/a
 
      7th Jan 2009
Peter,

As a matter of fact, the procedure : Private Sub ButtonGroup_Click()
is located in a class and I am calling it
from the very same userform ...
and in one instance, it has to call itself i.e. a CommandButton Click
will trigger automatically the next
CommandButton Click ...
Should I use your recommendation :
sProc = "CommandButton" & i & "_Click"
CallByName Me, sProc, VbMethod

Thanks again for your precious help
Cheers
Carim
 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      7th Jan 2009
> is located in a class and I am calling it
> from the very same userform ...


I don't quite follow but if the code is not in the class/userform that
contains the procedures, change 'Me' to an object reference that refers to
the class, eg

CallByName cls, sProc, VbMethod
where 'cls' refers to the class that contains the proc's

However if you are calling in the same class or userform as the procuderes,
indeed use the 'Me' keyword to refer to the class/userform
CallByName Me, sProc, VbMethod

Regards,
Peter T

PS yes, use the CallByName method if you need to call procedures in class or
userform, App.Run method wouldn't work

"Carim" <(E-Mail Removed)> wrote in message
news:383f777c-d594-4001-98bc-(E-Mail Removed)...
> Peter,
>
> As a matter of fact, the procedure : Private Sub ButtonGroup_Click()
> is located in a class and I am calling it
> from the very same userform ...
> and in one instance, it has to call itself i.e. a CommandButton Click
> will trigger automatically the next
> CommandButton Click ...
> Should I use your recommendation :
> sProc = "CommandButton" & i & "_Click"
> CallByName Me, sProc, VbMethod
>
> Thanks again for your precious help
> Cheers
> Carim



 
Reply With Quote
 
Carim
Guest
Posts: n/a
 
      7th Jan 2009
Peter,

Again you are right ... there is only one procedure
named Public Sub ButtonGroup_Click()
located in the class ( Class1 )
and the last instruction :
CallByName Me, "CommandButton" & z & "_Click", VbMethod
triggers a run-time error 438 ...
....
Thanks again for your help
Carim

 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      7th Jan 2009
Again I don't quite follow, is both "CommandButton" & z & "_Click" and the
CallByName code located in Class1. If so the code you posted should work,
assuming a Public procedure named
"CommandButton" & z & "_Click"
exists in the class

If you are trying to call ButtonGroup_Click, why not simply
Me.ButtonGroup_Click
or
cls.ButtonGroup_Click

See "CallByName" in help.

Regards,
Peter T

"Carim" <(E-Mail Removed)> wrote in message
news:41a1e2be-edb1-4f15-883b-(E-Mail Removed)...
> Peter,
>
> Again you are right ... there is only one procedure
> named Public Sub ButtonGroup_Click()
> located in the class ( Class1 )
> and the last instruction :
> CallByName Me, "CommandButton" & z & "_Click", VbMethod
> triggers a run-time error 438 ...
> ...
> Thanks again for your help
> Carim
>



 
Reply With Quote
 
Carim
Guest
Posts: n/a
 
      7th Jan 2009
Peter,

May I step back a little bit to let you know briefly about the
context ...
A Userform with 20 CommandButtons, which are all managed by a single
procedure :
Public Sub ButtonGroup_Click()
This procedure is located in the single class : Class1
Everything works fine but the very last instruction for a given random
CommandButton which has to act as if the user had clicked himself on a
another CommandButton ...
Hence, this loop I am trying to achieve ...whereby the procedure calls
back itself ...
Hope my explanation is clear enough ...
Cheers
Carim
 
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
Application.Evaluate (works with SIN but not RGB) Matthew Herbert Microsoft Excel Programming 4 14th Jan 2010 12:36 AM
Application.Evaluate question lcsma Microsoft Excel Programming 2 12th Dec 2008 01:21 PM
evaluate function only in Excel application x taol Microsoft Excel Programming 1 17th Mar 2008 09:53 PM
Alternatives to Application.evaluate(Long Formula) =?Utf-8?B?QXdpbGw=?= Microsoft Excel Programming 2 3rd Apr 2007 02:48 AM
Error 2015 with Application.Evaluate =?Utf-8?B?SmVmZg==?= Microsoft Excel Programming 3 6th Jun 2006 04:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:28 PM.