I'm trying to run an Excel Macro called Sheet1.Workbook_Open
from a .NET web system.
Below is my current code.
xlApp = New Excel.Application
xlWorkBook = xlApp.Workbooks.Open("C:\Testing\TempFile.xlsm")
xlWorkSheet = xlWorkBook.Worksheets("TestSpreadsheet")
Dim MacroName As String = "Sheet1.Workbook_Open"
xlApp.Run(MacroName)
Dim FileDate As String = SysdateTextBox.Text
FileDate = FileDate.Replace(" ", "")
FileDate = FileDate.Replace("/", "")
FileDate = FileDate.Replace(":", "")
FileName = "C:\Testing\File" & FileDate & ".xlsm"
xlWorkBook.SaveAs(FileName)
xlWorkBook.Close(True)
xlApp.Quit()
However, it fails on the line xlApp.Run(MacroName)
with the error;
Exception from HRESULT: 0x800A01A8
System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x800A01A8
Why is this happening, and how can I fix it? This error doesn't happen when the project is hosted on my local machine - only when it is on the server.