title: Enable Excel Macro in codes?
body: <p>I am working an existing project which is base do Excel class to copy values from one worksheet A to another one B. There are some formulas and Addin functions in ws A cells. The copy codes are used to copy only values out to ws B as a result. Here is a block of simplified codes:</p>
  
  <pre><code>using Excel = Microsoft.Office.Interop.Excel;
  ....
  
  object missing = System.Type.Missing;
  
  Excel.Application app = new Excel.Application();
  // Creating Excel application with source workbook in memory
  Excel.Workbook workbook = app.Workbooks.Open("SourceA.xls",
    Excel.XlUpdateLinks.xlUpdateLinksNever,....);
  ...
  
  app.Calculate() // Forcing to recalculate value in cells.
  ...
  
  //create destination workbook
  Excel.Workbook destWb = app.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
  Excel.WorkSheet destSheet = (Excel.Worksheet)destWb.Worksheets[1];
  Excel.Range destRange = (Excel.Range)destSheet.Cells[1, 1];
  //rename sheet 1
  destSheet.Name = "wsB Report";
  
  //Set Source Data Range from 
  Excel.WorkSheet sourceWA = (Excel.Worksheet)workbook.Worksheets["wsA"];
  //Get the predefined named range "DataRange" from source wsA
  Excel.Range sourceRange = sourceWA.get_Range("DataRange", missing);
  //copy data
  sourceRange.Copy(missing);
  
  //paste values and number formats
  destRange.PasteSpecial(Excel.XlPasteType.xlPasteValuesAndNumberFormats,
      Excel.XlPasteSpecialOperation.xlPasteSpecialOperationNone, missing, missing);
  //paste formats
  destRange.PasteSpecial(Excel.XlPasteType.xlPasteFormats,
      Excel.XlPasteSpecialOperation.xlPasteSpecialOperationNone, missing, missing);
  //paste column widths
  destRange.PasteSpecial(Excel.XlPasteType.xlPasteColumnWidths,
      Excel.XlPasteSpecialOperation.xlPasteSpecialOperationNone, missing, missing);
  ....
  
  destWb.SaveAs("destB.xls", missing, ....);
  </code></pre>
  
  <p>The problem I have is that the copies cells in destB.xls are all marked as "#NAME?". They should be values copied. I open the source excel file and I can see the data in the source range are updated with values. However, when I run my codes, the values seem not available.</p>
  
  <p>I guess that the Excel application I created in my codes may not have Macro enabled. This may be reason values cannot be copied. For example, when I open the source excel file, I'll see a prompt to enable or disable Macros. If I click on Enable button, the excel will take some time to display values in data cells.</p>
  
  <p>If that is the reason, is there any way in codes to enable Macro so that all formulas in cells will be able to update values?</p>
  
  <p>Another reason might be caused by OS or Windows security updates. Not sure if any Windows security settings may affect Excel macros. If this is the case, should I change Windows security level or any way to force Macros enabled in my project?</p>
  
  <p>By the way, my project runs in Windows XP and Windows 2008 Server, with Office Excel 2003 installed. The project was done in VS 2008.</p>