I'm writing a very basic WinForms app using VB.Net, everything is going smoothly until I try and open an Excel file that I've written to the tempLocation
via a Stream object (The workbook is in my project resources and the build action is set to "Embedded Resource")
Here's the code that causes the error:
Dim xlWBTemp As Excel.Workbook
Dim xlApp As Excel.Application
'// Below resolves to "C:UsersMacroManLockTemplate.xlsm"
Dim tempLocation As String = Environ("USERPROFILE") & "LockTemplate.xlsm"
...
xlWBTemp = xlApp.Workbooks.Open(tempLocation) '<~~ error here.
The error I get is:
System.Runtime.InteropServices.COMException was unhandled
ErrorCode=-2146827284
HResult=-2146827284
Message=Exception from HRESULT: 0x800A03EC
I've checked and the file definitely gets created, Excel is running and has already successfully opened a workbook at this point. I can't figure this out at all so any pointers truly welcome.
Update:
The file (tempLocation
) does exist in the correct location, but when I open it outside of the application, Excel gives me the "found unreadable content" error. The file does still open successfully and has no problems once opened. I can now get around this error by using the CorruptLoad
argument in the Workbooks.Open()
method but I feel this is blindly ignoring the issue.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…