title: Why excel open the closed wb if the macro to insert data to this closed wb is run from another wb with a table which connected to the closed wb?
body: <p>I've googled to find out why, but maybe because I'm limited in English - so I can not find the Google result with an article similar like mine.</p>
  <p>As I want to learn about ADO and data connection, so I'm playing around by making two workbooks : TABEL.xls and test.xlsm <br></p>
  <p>TABEL.xls has a sheet name &quot;Item&quot; with two columns header in cell A1 &quot;Item&quot; and in cell B1 &quot;Unit&quot;. There is one data in cell A2 and B2, say : &quot;Fish&quot; and &quot;Kg&quot;. This workbook is close.</p>
  <p>In test.xlsm, I have this kind of macro :</p>
  <pre><code>Sub test()
  Dim conn As New Connection, rs As New Recordset
  
  vl1 = &quot;sapi&quot;
  vl2 = &quot;Ons&quot;
  pf = &quot;D:\Laporan DarmaPangan\TABEL.xls&quot;
  
  conn.Open &quot;Provider=Microsoft.Jet.OLEDB.4.0;&quot; &amp; _
  &quot;Data Source=&quot; &amp; pf &amp; _
  &quot;;Extended Properties=&quot;&quot;Excel 8.0;HDR=yes;&quot;&quot;&quot;
  
  sqlstr = &quot;insert into [Item$](Item,Unit)&quot; &amp; _
  &quot;values ('&quot; &amp; vl1 &amp; &quot;', '&quot; &amp; vl2 &amp; &quot;')&quot;
  
  rs.Open sqlstr, conn, 1, 3
  'rs.Close (throw me an error &quot;it already closed&quot;)
  conn.Close
  End Sub
  </code></pre>
  <p>When I run the macro above, it didn't automatically open the TABEL.xls ... and when I open the TABEL.xls manually, I see the result where the item &quot;sapi&quot; is in cell A3 and unit &quot;ons&quot; is in cell B3. There's no problem here. I close back the TABEL.xls</p>
  <p>Next, I'm playing around to try a connection from test.xlsm to TABEL.xls. So, within the test.xlsm : via Data tab in Excel ---&gt; Existing Connection ---&gt; Browse For More ---&gt; I choose the TABEL.xls and choose the Item name, and choose Table view and Sheet1 cell A1 as the location.</p>
  <p>So now in test.xlsm Sheet1, I have a table with the header &quot;item&quot; and &quot;unit&quot;, also with a data &quot;Fish&quot; - &quot;Kg&quot; in cell A2 and B2 and also the newly inputted data &quot;sapi&quot; - &quot;ons&quot; in cell A3 and B3.</p>
  <p>Now the thing which I thought in my mind is like this :<br>
  After I run the macro again with another item &amp; unit value, the macro will put this data into TABEL.xls without opening the workbook. And when I click the Refresh All button, the table in Sheet1 will show the newly inputted data in cell A4 and B4.</p>
  <p>But I was wrong, as it turn out : when I run the macro in test.xlsm, it automatically open TABEL.xls as read only. I see the newly inputted data in cell A4 and B4 in TABEL.xls .... but since this workbook is in read only mode, this new data is not saved yet which of course I can't just save it. So, even after clicking the Refresh button of course it didn't show an updated data table.</p>
  <p>The next thing what I did : <br>
  I make a new workbook and have the same macro in this new workbook.<br>
  Close the test.xlsm and close the TABEL.xls.<br></p>
  <p>Then I run the macro from this new workbook. This time, it didn't automatically open the TABEL.xls. Then I open the test.xlsm and after clicking the Refresh button, I see the new data in cell A4 and B4 within Sheet1.</p>
  <p>I seems that <em>if a workbook (in this case test.xlsm) has a table connection to another workbook (in this case TABEL.xls) and IF the macro like above is run within the same workbook, then the macro won't give an expected result as it will automatically open the TABEL.xls as read only.</em></p>
  <p>So my question : <br>
  Is it actually my italic sentence a &quot;default rule&quot; which I should've known before and I shouldn't do it ? If yes, would somebody please explain it to me why is that ?</p>
  <p>Or is it actually shoudn't happen like that ? So, maybe there's something which I should do ? A wrong macro code maybe ?</p>
  <p>Any kind of help would be greatly appreciated.<br>
  Thank you in advanced.</p>