vba equivilant of eval / execute

davestewart

New Member
Joined
Feb 15, 2006
Messages
43
Hi All,
Sorry if this has been asked before - I've tried searching the forum with no luck.

Is there a VB(A) equivilant?

I'd like to be able to such things as:

theSub="mySub"
Eval(theSub)

and a whole host of other things you would take for granted in other languages.

Thanks,
Dave
 
Well if it was an image on say a userform you could reference it like this,
using the forms Controls collection.
Code:
MyVar = "redImage"
Set ctl = Me.Controls(MyVar)
There are various other collections of objects.

Don't know if that helps at all.:)
 
Upvote 0

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Dave,

Yes, I do understand the usefulness of what you're saying. And I initially missed this functionality when I started doing all of my programming activities in VBA. I guess I've just learned to "program around" it. Tushar's a much stronger coder than I and could probably engage you in a more esoteric discussion of the strengths and weaknesses of coding like that. (Like I said, I missed not having it initially, but then again, some of my code would probably make Tushar groan.)

Norie,

Not to be rude, but if the dude can write code in a dozen languages, I'd assume he knows how to reference objects in a collection by setting a string variable to their name.
 
Upvote 0
That sounds like a reasonable workaround.
I'm sure once I get more into this project I'll have more related questions - for now it's a bit of an exploratory investigation.

Thanks !
 
Upvote 0
> "esoteric discussion of the strengths and weaknesses of coding like that."

God No! Actually I quite enjoy programming. Why take the fun out of it!? ;)
 
Upvote 0
LOL - then watch out for Nate. [Brilliant chap (seriously) but the man does enjoy a good discussion on how to shave a <sup>1</sup>/<sub>10</sub> of a second off of a process you'll run once a month. :-D ]
 
Upvote 0
Hello,
Hahahaa... thanks for the info Greg. I'll be sure to see him before he sees me! ;)
Heh, not likely. :lol: ;)

Code:
' evaluate the string "myVar1" to get a reference to the variable "myVar1"

I guess it's not possible, otherwise someone would know what I'm talking about.

So how do you VB guys dynamically create a reference to a variable? Or can't you?
Oh, it probably is possible. Desirable? Not so sure...

Nevertheless, VBA's CallByName Function may be in the direction you are looking.
Could be, Tom, e.g.,

http://www.mrexcel.com/board2/viewtopic.php?t=176258

As you can see in the linked thread, there are generally more straightforward approaches with VBA. You're engaging in a hatchet fight without a hatchet.

http://vb.mvps.org/hardcore/html/bringyourhatchet.htm

:-?
 
Upvote 0
Now, I find that funny. :lol: I make one wise-*** remark about Nate and he shows up with the answer in his pocket. (Figures that Chip would know right how to do this.) To quote one of Nate's favorite McDonald's jingles -- "I'm lovin' it!"
 
Upvote 0
Thanks chaps,
Very nice of you both to jump in and have a decent discussion. I gotta say these threads move pretty quickly and I appreciate you coming back and adding your responses.

Nate, I'll check out your links at some point when I'm not too frantic - probably some time around 2010 ;) and Greg - thanks for the continued input.

Perhaps at some point once I'v egot some quality VB under my belt I'll be able to give something back myself. My day job is as an animator / programmer ... I'm can usually be found in a well known 3D scripting forum.

Cheers for now!
Dave
 
Upvote 0
You're welcome, and sure, take your time. :)

I try to keep it friendly, even when Greg does make fun of me... And hey, what's wrong with good habbits and fast code?! :-P 8-)

Incidentally, this might not be a good habbit, you're hacking around native/expected functionality in VBA in a big way, here...
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top