VBA how to run a string as a line of code

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

    Visual Basic is a compiler language, and as such does not support the ability to execute human-readable code while it is running. All code written in VBA must first be compiled BEFORE the program runs the first time. However, SQL is an interpreter language, and can be handed code which it will execute line by line. You can also fetch contents for variables from other sources while the program runs, you just can't build a string while the program is running and then execute it in VBA directly.

提交回复
热议问题