title: VBA macro which writes a new macro from string on the fly
body: <p>Is it possible to create Excel VBA macro from a string variable?</p>
  
  <p>Suppose we have FirstMacro:</p>
  
  <pre><code>Sub FirstMacro()
      Dim MyString
      MyString = "Sub SecondMacro()" &amp; Chr(13) &amp; Chr(10) &amp; "MsgBox " &amp; Chr(34) &amp; "Hello" &amp; Chr(34) &amp; Chr(13) &amp; Chr(10) &amp; "End Sub"
      Debug.Print MyString
      'Here be code that magicly creates SecondMacro
  End Sub
  </code></pre>
  
  <p>Running the macro, I want to create SecondMacro which is stored in VBA string variable. The second macro can be created either below in the same module or in a new module. </p>
  
  <p>So the second macro from string looks like this:</p>
  
  <pre><code>Sub SecondMacro()
  MsgBox "Hello"
  End Sub
  </code></pre>