Strange Issue with Excel Interop
I have recently moved to 2005 Studio Standard edition and after some fighting initally with my laptop and it's issues with VS2005 and left over beta bits and so on, I have totally rebuilt my machine.
In short = fresh copy of xp pro and VS2005 std and Office 2003
IIn VB 2003 I used to be able to add a reference to the Excel 11.0 library and then use the following line:
Imports
Microsoft.Office.InteropHowever that is not possible any more. Following the same steps I can only import the following:
Imports
Microsoft.Office.CoreThis presents a problem if I want to do this, because the Interop is not available:
Dim xlAppAs Excel.ApplicationDim xlBookAs Excel.Workbook
Dim xlSheetAs Excel.Worksheet
So the Excel. anything is not defined
I have found some OfficeXP development stuff on Microsoft's website, which basically is all the interops available for office. Installed without problems and if I include the reference to Microsoft.Office.Interop.Excel the I can use the above mentioned code.
However if I try to use this
xlBook.SaveAs(
"C:\test.xls")I get this error:
System.Runtime.InteropServices.COMException was unhandled
ErrorCode=-2147417851
Message="The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))"
Source="Interop.Excel"
I have no idea what is going on and any help will be appreciated
Here is the whole code:
Imports
System.IOImports Microsoft.Office.Interop
Public
Class Form1Dim xlAppAs Excel.ApplicationDim xlBookAs Excel.Workbook
Dim xlSheetAs Excel.WorksheetPrivateSub Button1_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles Button1.Click
OpenExcel()
PlayTime()
CloseExcel()
Debug.WriteLine("DONE")
EndSubSub OpenExcel()
xlApp =CType(CreateObject("Excel.Application"), Excel.Application)
EndSubSub CloseExcel()
xlApp.Quit()
xlApp =Nothing
EndSubSub PlayTime()
If File.Exists("C:\test.xls")Then
File.Delete("C:\test.xls")
EndIf
xlBook = xlApp.Workbooks.Add()
xlSheet =
xlSheet.Name ="Iggy"
xlBook.SaveAs("C:\test.xls")
EndSub
End
Class
