OK, this creates and closes the file.
private static void CreateWorkbook(string fileName, string macro)
{
try
{
if (File.Exists(fileName)) { File.Delete(fileName); }
GC.Collect();
var excelxl = new Excel.Application();
Excel.Workbook workBook = excelxl.Application.Workbooks.Add();
var sheet = (Excel._Worksheet)workbk.ActiveSheet;
var module = workBook.VBProject.VBComponents.Add(VBIDE.vbext_ComponentType.vbext_ct_StdModule);
module.CodeModule.AddFromString(macro);
excelxl.Visible = false;
excelxl.UserControl = false;
workBook.Close(true);
}
catch (Exception ex)
{
Alerts.Error("File was not created", "Error", ex);
}
}
Don't know if that helps any?
Bookmarks