Thread: String to code
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default String to code

You can't build a line of code dynamically and then executed it in most
cases.

If the problem is you need to build the array dynamically, rather than
concatenating the string together do this

Dim myArray as Varian
Dim sh as worksheet
for each sh in worksheets
if somecondition then
if not isarray(myArray) then
redim myArray(0 to 0)
myArray(0) = sh.name
else
redim preserve myArray(0 to ubound(myArray,1)+1)
myArray(ubound(myArray)) = sh.name
end if
end if
Next
Sheets(myArray).Move after:=Sheets("StartAkk")

--
Regards,
Tom Ogilvy


"Factivator" wrote in message
...
Hello,

Probably a stupid question, but I don't seem to be able to fix it myself.

I have build a line of code in VBA, based on some cell content (selection

of
sheets in a workbook), and now I have, in a string-defined variable, the
appropriate code, which I can check with debug.print. The variable, named
txt1, contains the text

Sheets(Array("Data02", "Data03")).Move after:=Sheets("StartAkk")

which is actually what I want to do (the actual sheet names selected will
change at runtime according to some "flags" set in a worksheet).

But now I need to execute that line of code, ie., "activate" the content

of
txt1.

How do I do that ?


Thank you very much in advance !


Morten Jansen