VBA how to run a string as a line of code

前端 未结 4 1276
余生分开走
余生分开走 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:26

    It's not exactly what I was asking, I ended up going a slightly different direction, but here's what I ended up doing and it would probably be easily altered to more closely match my question. I actually took lines of text from an external text file and inserted them into a line of code. What I was doing in this example was just hiding columns, the external text file was a list of column names. (figuring out how to output that was fun too)

    Open "C:\UserList.txt" For Input As #TextFile
    While Not EOF(TextFile)
    Line Input #TextFile, TextLine
    Screen.ActiveDatasheet.Controls(TextLine).ColumnHidden = True
    Wend
    

提交回复
热议问题