title: Write data to excel and change sheet name using ActiveX--Matlab
body: <p>I need to export data to excel sheet with a specific name using Activex. Here is what I did: First i export the data to excel in first for loop and then modify the names of the sheet using second for loop. Can it be done even in one single for loop? I think there should be another better idea. 
  <strong>Note: The size of the data varies.</strong></p>
  
  <pre><code>try
      filename = fullfile(pwd,'example.xlsx');
      for i=1:5
          xlswrite(filename,[1 2;3 4]*i,i);
      end
      for i = 1:5
          myExcel = actxserver('Excel.Application');
          excelWorkBook = myExcel.Workbooks.Open(filename,0,false);
          excelWorkBook.Worksheets.Item(i).Name = ['new_sheet_' num2str(i)]; 
          excelWorkBook.Save;
          excelWorkBook.Close;
          myExcel.Quit;
      end
  
  catch
      % Disp Error message.....
  end
  </code></pre>