VBA how to run a string as a line of code

前端 未结 4 1275
余生分开走
余生分开走 2020-12-21 01:24

Is there a way to convert a string into an executable line of code?

something like:

Dim Line1 as String
Line1 = \"MsgBox (\"\"Hello\"\")\"
Execute Li         


        
4条回答
  •  北海茫月
    2020-12-21 02:12

    You didn't have to go through such extremes... as you are not actually dynamically executing code. The Controls() Property accepts a test string so you could have used any source including a much simpler table, or array.

    The same thing could have been accomplished as in your initial example like so:

    Dim Line1 as String
    Line1 = "Hello"
    MsgBox Line1
    

提交回复
热议问题