
execute a variable as a function/sub procedure (like eval function in java(script))
Hi Marco,
Here's a routine developed by former Word MVP Will Rickards. I've never used
it but perhaps it will be of help to you.
Public Sub EVAL(ByVal strToEvaluate)
Dim comNew As VBIDE.VBComponent
With ThisDocument.VBProject.VBComponents
Set comNew = .Add(vbext_ct_StdModule)
With comNew.CodeModule
.InsertLines .CountOfLines + 1, "Public Sub EVAL_RUNTIME()" & _
strToEvaluate & vbcr & "End Sub"
End With
End With
Application.Run "EVAL_RUNTIME"
ThisDocument.VBProject.VBComponents.Remove comNew
End Sub
--
Bill Coan
Microsoft Word MVP
http://www.wordsite.com
Quote:
Quote:
> Hello
> Is it possible in VBA to execute a string/variable if there is a function
> with that name?
> for example:
> Function DisplayMsg(aMsg as string) as string
> MsgBox aMsg
> DisplayMsg = "Yes"
> End Sub
> execute the function:
> dim x as string
> dim y as string
> x = "DisplayMsg("This is a message")"
> y = x
> I just realise.... this could be possible when you're using the Word.Basic
> procedure, but how long is this function supported by Microsoft in VBA??
> Regards,
> Marco Dissel