title: Editing and Saving Excel file from Matlab
body: <p>I need to generate a code in Matlab to Edit and then save an Excel file.  The code has to do the following:</p>
  
  <ol>
  <li><p>Open the Excel file</p></li>
  <li><p>Go to the second sheet (sheet2)</p></li>
  <li><p>Change the value of cell A2</p></li>
  <li><p>Go to the first sheet (sheet1)</p></li>
  <li><p>Save the sheet1 as a tab delimited text file (.txt)</p></li>
  </ol>
  
  <p>Sheet 1 contains cells which depend on the cell A2 in sheet2 (I need to do this several times for different values of sheet2-A2, that's why I need to code it).</p>
  
  <p>Browsing the web, I have been able to code steps 1-4 (see code bellow). However, I have not been able to find the way to do 5. I would very much appreciate your help. Thank you!!</p>
  
  <hr>
  
  <pre><code>% Open Excel Server:    
  Excel = actxserver('Excel.Application');     
  
  % Makes Excel visible in the screen:    
  set(Excel, 'Visible', 1);     
  
  % Open Excel file:    
  Workbooks = Excel.Workbooks.Open('E:\TEST.xlsx');     
  
  % Make the second sheet active:    
  Sheets = Excel.ActiveWorkBook.Sheets;    
  sheet2 = get(Sheets, 'Item', 2);    
  invoke(sheet2, 'Activate');    
  
  % Get a handle in the active sheet:    
  Activesheet = Excel.Activesheet;
  
  
  % Edit cell A2:    
  A = 2;    
  ActivesheetRange = get(Activesheet,'Range','A2');    
  set(ActivesheetRange, 'Value', A);    
  
  pause(5) %Pauses the code for 5 seconds (so sheet 1 updates the formulas)
  
  
  % Going to Sheet1 where the focal data is:    
  Sheets = Excel.ActiveWorkBook.Sheets;    
  sheet1 = get(Sheets, 'Item', 1);    
  invoke(sheet1, 'Activate');
  </code></pre>
  
  <hr>