title: How can I get back a previously created Excel ListObject?
body: <p>I am creating a ListObject in Excel using VSTO as follows:</p>
  
  <pre><code>ListObject lo = ws_vsto.Controls.AddListObject(range, "MyList");
  </code></pre>
  
  <p>(The range variable is a previously defined range.)</p>
  
  <p>If I then loop through the worksheet Controls collection I can find that ListObject.</p>
  
  <p>However, if I save the workbook and reopen it, the Controls collection is empty. How can I get this ListObject back after re-opening so that I can continue working with it?</p>
  
  <p>EDIT</p>
  
  <p>I've got a bit further:</p>
  
  <pre><code>        var wb = Globals.ThisAddIn.Application.ActiveWorkbook;
          var wb_vsto = wb.GetVstoObject();
  
  
          foreach (Excel.Worksheet ws in wb.Worksheets)
          {
              var wsv = ws.GetVstoObject();
              foreach (Excel.ListObject l in ws.ListObjects)
              {
                  MessageBox.Show(l.Name);
                  var lo = wsv.Controls.AddListObject(l);
                  Excel.Range range = lo.Range;
                  range.Activate();
             }
          }
  </code></pre>
  
  <p>When I get to the var lo = line, I have a ListObject added to the Controls collection and available for use. However, it's DataSource property holds null. Is there an easy way to get the original data source back?</p>
  
  <p>I then thought about rebuilding the data source from the information in the range. The range.Activate() line selects the list in Excel (so I know it has the right thing). However, I can't for the life of me work out how to get the data out of that range and get the address of the range. The MSDN documentation talks about the Address property but this doesn't appear to actually exist. (MSDN documentation for VSTO seems ropey at best).</p>