title: Programmatically update the code of a CodeModule. Issue with character "_" in original copied code
body: <p>I am updating the code of a module copying it from another module. I replace the whole code.
  Actually, the code is in a sheet (both original and destination), not in a module.</p>
  <p>The piece of code that copies it is:</p>
  <pre><code>Dim codeModDestination As CodeModule
  Dim codeModOriginal As CodeModule
                  
  '..... Set CodeModules, etc.
                  
  'Delete the existing code at the destination CodeModule    
  codeModDestination.DeleteLines 1, codeModDestination.CountOfLines 
  
  Dim fila As Long
  For fila = 1 To codeModOriginal.CountOfLines
      codeModDestination.InsertLines codeModDestination.CountOfLines + 1, _
                                     codeModOriginal.Lines(fila, 1)
  Next fila
  </code></pre>
  <p>It copies the whole code of the original module, but the lines split with the character &quot;_&quot; get a blank line between them, making a code that launches a compile error:</p>
  <p>Original code:</p>
  <pre><code>    Msgbox &quot;Hello&quot; + vbLf + _
          &quot;World&quot;
  </code></pre>
  <p>Is transformed into:</p>
  <pre><code>    Msgbox &quot;Hello&quot; + vbLf + _
  
          &quot;World&quot;
  </code></pre>
  <p>All other code is copied correctly, but I can't get into Interruption mode, so I don't know what is going on.</p>
  <p>EDIT:</p>
  <p>I found a workaround, but I am not sure why it works:</p>
  <pre><code>Dim fila, insert_before As Long
  insert_before = 0
  For fila = 1 To codeModOriginal.CountOfLines
      codeModDestination.InsertLines codeModDestination.CountOfLines + 1 - insert_before, _
                                     codeModOriginal.Lines(fila, 1)
      insert_before = 0
      If fila &lt;&gt; codeMod.CountOfLines Then
          debug.print fila
          insert_before = 1
      End If
  
  Next fila
  </code></pre>
  <p><code>insert_before</code> is 0 for the first 20 lines, until the first instruction with &quot;_&quot; is found. Then it is always 1.</p>