object oMissing = System.Reflection.Missing.Value;
MessageBox.Show("The excel file about to open");
Excel.ApplicationClass oExcel = new Excel.ApplicationClass();
oExcel.Visible = true;
Excel.Workbooks oBooks = oExcel.Workbooks;
Excel._Workbook oBook = null;
MessageBox.Show("opening excel sheet");
oBook = oBooks.Open(fileName, oMissing, oMissing,oMissing,oMissing,oMissing,oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
MessageBox.Show("THE FILE IS OPEN");
MessageBox.Show("Macro about to be run");
RunMacro(oExcel, new Object[] { "Macro1" });
MessageBox.Show("the macro is completed");
oBook.Close(false, oMissing, oMissing);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook);
oBook = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBooks);
oBooks = null;
oExcel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel);
oExcel = null;
這段代碼打開一個空白的excel窗口,而不是打開的文件。 宏也被定義。我不斷收到一個空白excel打開錯誤,沒有打開文件
您可以避免所有這些oMissing '參數,如果你使用'動態'類型。添加它是爲了使互操作更容易。 –
我曾嘗試刪除這些,仍然出現相同的錯誤。 –