title: VBA how to run a string as a line of code
body: <p>Is there a way to convert a string into an executable line of code?</p>
  
  <p>something like:</p>
  
  <pre><code>Dim Line1 as String
  Line1 = "MsgBox (""Hello"")"
  Execute Line1
  </code></pre>
  
  <p>resulting in the pop up box saying Hello.</p>
  
  <p>What I'm doing is pulling lines out of a text file.  I can pull lines that are the names of form controls and use them to perform actions on those form controls but I'd like to go one step further and execute lines.
  I've seen claims that this would work:</p>
  
  <pre><code>Application.Run Line1
  </code></pre>
  
  <p>or make the variable an array and store it in element 1 e.g. and use</p>
  
  <pre><code>Application.Run Line1(1)
  </code></pre>
  
  <p>but it doesn't work for me.</p>
  
  <p>Ok, while writing this I've also been experimenting.  I found that</p>
  
  <pre><code>Eval (Line1)
  </code></pre>
  
  <p>will work when Line1 is a message box, but not when it is something like:</p>
  
  <pre><code>line1 = "DoCmd.OpenForm ""form1"""
  </code></pre>
  
  <p>Any tips would be appreciated.</p>
  
  <p>Thanks</p>