Pls help ~ Silly Question

V

vbaNOOB

Hi all,

I'm thinking if I could execute a line as command in vba (Sorry for my bad
english)

Ex:
Dim str As String
str = "msgbox " & Chr(34) & "hihi" & Chr(34)

As u can see, str contain sth like this : msgbox "hihi"
And it's valid vba command.

Is that a way that I can execute the str as a command in vba
If my memory serve me well, I can do this in visualfoxfro
But I just forget the syntax.

Many thanks
 
L

Lene Fredborg

I am not sure what you want - do you want to display "hihi" as a message in a
dialog box?
If that is correct, you only need the following code line:

MsgBox "hihi"

For more information about the MsgBox function, see the VBA help.

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
J

Jonathan West

vbaNOOB said:
Hi all,

I'm thinking if I could execute a line as command in vba (Sorry for my bad
english)

Ex:
Dim str As String
str = "msgbox " & Chr(34) & "hihi" & Chr(34)

As u can see, str contain sth like this : msgbox "hihi"
And it's valid vba command.

Is that a way that I can execute the str as a command in vba
If my memory serve me well, I can do this in visualfoxfro
But I just forget the syntax.

Many thanks

Look up the CallByName method and the Run method in the VBA help.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
J

Jonathan West

Lene Fredborg said:
I am not sure what you want - do you want to display "hihi" as a message in
a
dialog box?

I get the impression that he wants to be able to dynamically build a line of
code in a string variable, and then execute that newly-built line of code.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
E

Ed

Hi vbaNOOB,

Probably not relevant to your purposes, but you can do it in VBScript using
the "execute" command.

E.g.

str="MsgBox " & chr(34) & "hihi" & chr(34)

execute str

Cheers.

Ed
 
V

vbaNOOB

First, thanks for all the reply, really close to my target ^^

For the CallByName Function:

Executes a method of an object, or sets or returns a property of an object.
Syntax
CallByName(object, procname, calltype,[args()])

Is that mean I can only control the procname by string only?
I'm not sure how I can achieve my goal by CallbyName function, any more hints?

For the execute command in vbscript,

that's the command I need, but it's in vbscript.
Is there any way I can use it in vba

Many thanks
 
E

Ed

Hi vbaNOOB,

As far as I know, VBA has no exact equivalent of VBScript's "execute"
function. I'm not sure if CallByName can be used to execute just any piece of
text in a string variable - I've never used it and the VBA Help is not a lot,
but it looks to me that you may be able to do some things with it but not
others.

If you post the details of the particular type of thing you're trying to do
(if that is something other than "create a general-purpose string variable
execution mechanism") someone may be able to suggest a way.

Regards.

Ed

vbaNOOB said:
First, thanks for all the reply, really close to my target ^^

For the CallByName Function:

Executes a method of an object, or sets or returns a property of an object.
Syntax
CallByName(object, procname, calltype,[args()])

Is that mean I can only control the procname by string only?
I'm not sure how I can achieve my goal by CallbyName function, any more hints?

For the execute command in vbscript,

that's the command I need, but it's in vbscript.
Is there any way I can use it in vba

Many thanks


vbaNOOB said:
Hi all,

I'm thinking if I could execute a line as command in vba (Sorry for my bad
english)

Ex:
Dim str As String
str = "msgbox " & Chr(34) & "hihi" & Chr(34)

As u can see, str contain sth like this : msgbox "hihi"
And it's valid vba command.

Is that a way that I can execute the str as a command in vba
If my memory serve me well, I can do this in visualfoxfro
But I just forget the syntax.

Many thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top