Trying to get a basic VB.NET Excel file creation app working, starting from some sample code from here, I'm getting err msgs with this code:
Private Sub ButtonCreateExcelFile_Click( sender As Object, e As EventArgs) Handles ButtonCreateExcelFile.Click
Dim xlApp As New Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Dim misValue As Object = System.Reflection.Missing.Value
xlWorkBook = xlApp.Workbooks.Add(misValue)
xlWorkBook.Application.Visible = True
xlWorkBook.Application.ScreenUpdating = False
xlWorkSheet = xlWorkBook.Sheets("sheet1")
'xlWorkSheet.SaveAs("C:\vbexcel.xlsx")
xlWorkSheet.SaveAs("C:\\misc\\vbexcel.xls")
. . .
I first had tried this:
xlWorkSheet.SaveAs("C:\vbexcel.xlsx")
(failing to escape the backwhack), and this ("vbexcel.xlsx") was somehow mistaken for "52587100" as you can see here:
System.Runtime.InteropServices.COMException was unhandled
ErrorCode=-2146827284
HelpLink=C:\Program Files (x86)\Microsoft Office\Office12\1033\XLMAIN11.CHM
HResult=-2146827284
Message=Microsoft Office Excel cannot access the file 'C:\52587100'. There are several possible reasons:
• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as a currently open workbook.
Source=Microsoft Office Excel. . .
By adding a subfolder to the path, and the escape characters, like so:
xlWorkSheet.SaveAs("C:\\misc\\vbexcel.xlsx")
...I got a similar error, but this time it just says it cannot access the file (without claiming the file name is named "52587100"):
System.Runtime.InteropServices.COMException was unhandled
ErrorCode=-2146827284
HelpLink=C:\Program Files (x86)\Microsoft Office\Office12\1033\XLMAIN11.CHM
HResult=-2146827284
Message=The file could not be accessed. Try one of the following:
What is wrong with this code, that is preventing the file from being accessible?