title: CodeModle.Insertlines drops variables
body: <p>After several days of searching Excel vba forums I have finally given in and must now ask for help.</p>
  <p>The problem is that CodeModle.Insertlines causes excel to drop all variables. I have a couple arrays that I need to use / check boxes and list boxes etc. all get wiped when I run the code below</p>
  <pre><code>            With Application.Workbooks(ActiveWorkbook.Name).VBProject.VBComponents(&quot;UserSavedQueries&quot;).CodeModule
                  .InsertLines 2, &quot;tmp = &quot; &amp; &quot;&quot;&quot;&quot; &amp; &quot;THIS IS SOME SAMPLE TEXT &quot; &amp; &quot;&quot;&quot;&quot;
              End With
  </code></pre>
  <p>I fully admit that the Insertlines was a bit of a work around as a way to an end, but that way now seems blocked. Please can someone advise how to insert lines into a module without resetting all variable?</p>
  <p>For the bigger picture (and for someone to advise how I probably should have tackled this in the first place)</p>
  <ul>
  <li>I have a sheet that pulls together a bunch of parameters from list boxes, checkboxes cells etc when a user selects the ‘Go’ button.</li>
  <li>the selections are formatted to make a JSON message that is sent to an API and the response is displayed in a table on a second sheet.</li>
  </ul>
  <p>To give some context,  Imagine Listbox1 called “search criteria” with selections of “Manufacturer, Colours, Countries”. Listbox2 called “Filters” changes context depending on the selection on Listbox1. So we could have for Listbox2: “Ford, BMW, Nissan” , “Red, Blue, Green, Black, White”, “ ”. Not the actual data but it shows the varying length of each selection. There are actually around 12 available selections some of which have 100+ filter options.
  The user may select “Ford, Red” which would return red Fords in all countries or “Ford,BMW,Green,Scotland” which would just Green Fords and BMWs in Scotland.</p>
  <ul>
  <li>All of this works nicely.</li>
  </ul>
  <p><strong>NOW</strong>: I need to add the ability to have “Saved User Selections”. I need to avoid dumping these selections in a worksheet (even hidden) as it allows the user to “fiddle” with the shape and format of the  selection which will break the JSON parsing. So I decided to save the user selections in a VB module. A UserForm provides the ability to Name the saved selection, date-stamp it and runs  the code above. Parsing the UserSavedQueries module returns a listbox of all saved selections, which, when double-clicked are intended to populate listbox1 &amp; 2 ready for the user to hit  ‘Go’.</p>
  <ul>
  <li>Considered options: I haven’t ruled out saving to an external file, or maybe even registry, but would prefer to keep self-contained within the one file.</li>
  </ul>
  <p><a href="https://stackoverflow.com/questions/6089178/module-variables-dont-survive-codemodule-insertlines-call">This article</a> came closest to helping, but I'm not sure how it would work for my use-case</p>