title: C# read/write .xlsm Files
body: <p>Hi i try to work with Excel files and C#. Right now i can work with xlsx files and can open it and so on. But when i change it to xlsm Files i always get an exception that the files where not found and i have no clue why. Here is my code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using DocumentFormat.OpenXml.Packaging;
  using DocumentFormat.OpenXml.Spreadsheet;
  using Excel = Microsoft.Office.Interop.Excel;
  using Microsoft.Office.Interop;
  using System.Reflection;
  using System.Windows.Forms;
  using System.Diagnostics;
  
  namespace WorkWithExcel
  {
      class reportingController
      {
  
          public void createExcelFile()
          {
              Excel.Application oXL = new Excel.Application();
  
              Excel.Workbook oWB = oXL.Workbooks.Add(Missing.Value);
  
              oWB.SaveAs(Application.StartupPath + "\\PROJEKTSTATUS_GESAMT_neues_Layout.xlsm", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Excel.XlSaveAsAccessMode.xlNoChange, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
  
              oWB.Close(true, Missing.Value, Missing.Value);
          }
  
          public void openExcelFile()
          {
              Excel.Application oXL = new Excel.Application();
  
              Excel.Workbook oWB = oXL.Workbooks.Open(Application.StartupPath + "PROJEKTSTATUS_GESAMT_neues_Layout.xlsm", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
  
              //read Excel sheets 
              foreach (Excel.Worksheet ws in oWB.Sheets)
              {
                  MessageBox.Show(ws.Name);
              }
  
              //save as separate copy 
              oWB.SaveAs(Application.StartupPath + "\\PROJEKTSTATUS_GESAMT_neues_Layout_neu.xlsm", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Excel.XlSaveAsAccessMode.xlNoChange, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
  
              oWB.Close(true, Missing.Value, Missing.Value);
          }
  
          public void writeExcelFile()
          {
              Excel.Application oXL = new Excel.Application();
              Excel.Workbook oWB = oXL.Workbooks.Open(Application.StartupPath + "\\PROJEKTSTATUS_GESAMT_neues_Layout.xlsm", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
              Excel.Worksheet oWS = oWB.Worksheets[1] as Excel.Worksheet;
  
              //rename the Sheet name 
              oWS.Name = "Excel Sheet";
  
              for (int i = 1; i &lt; 10; i++)
              {
                  oWS.Cells[i, 1] = "Cell " + i.ToString();
              }
              oWB.SaveAs(Application.StartupPath + "\\PROJEKTSTATUS_GESAMT_neues_Layout.xlsm", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Excel.XlSaveAsAccessMode.xlNoChange, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
  
              Process.Start(Application.StartupPath + "\\PROJEKTSTATUS_GESAMT_neues_Layout.xlsm ");
          }
  
          public void readExcelFile()
          {
              Excel.Application oXL = new Excel.Application();
  
              Excel.Workbook oWB = oXL.Workbooks.Open(Application.StartupPath + "\\PROJEKTSTATUS_GESAMT_neues_Layout.xlsm", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
  
              Excel.Worksheet oWS = oWB.Worksheets[1] as Excel.Worksheet;
  
              Excel.Range range;
  
              range = oWS.UsedRange;
  
              //read first row, first cell value 
              MessageBox.Show((string)(range.Cells[1, 1] as Excel.Range).Value2);
          }
  
      }
  }
  </code></pre>
  
  <p>And here is the exeption:</p>
  
  <pre><code>An exception of type 'System.Runtime.InteropServices.COMException' occurred in WorkWithExcel.exe .
  
  Additional information: ' C : \ Users \ AAN \ Documents \ Visual Studio 2015 \ Projects \ Work With Excel \ Work With Excel \ bin \ DebugPROJEKTSTATUS_GESAMT_neues_Layout.xlsm ' was not found. Check the spelling of the filename , and verify that the file location is correct .
  </code></pre>
  
  <p>But the file is there.</p>
  
  <p>With an .xlsx file it works but not with an xlsm. So any help would be great. So i tried to google and some blogs but nothing worked for me. Mabey there is something i dont get....</p>
  
  <p>Thanks for your time and sorry for my english.</p>