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.Interop

However that is not possible any more. Following the same steps I can only import the following:

Imports Microsoft.Office.Core

This presents a problem if I want to do this, because the Interop is not available:

Dim xlAppAs Excel.Application
Dim 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.IO
Imports Microsoft.Office.Interop

PublicClass Form1

Dim xlAppAs Excel.Application
Dim xlBookAs Excel.Workbook
Dim xlSheetAs Excel.Worksheet

PrivateSub Button1_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles Button1.Click
OpenExcel()
PlayTime()
CloseExcel()
Debug.WriteLine(
"DONE")
EndSub

Sub OpenExcel()
xlApp =
CType(CreateObject("Excel.Application"), Excel.Application)
EndSub

Sub CloseExcel()
xlApp.Quit()
xlApp =
Nothing
EndSub

Sub PlayTime()
If File.Exists("C:\test.xls")Then
File.Delete("C:\test.xls")
EndIf

xlBook = xlApp.Workbooks.Add()
xlSheet =
CType(xlBook.Worksheets(1), Excel.Worksheet)
xlSheet.Name =
"Iggy"
xlBook.SaveAs("C:\test.xls")
EndSub

EndClass

[5434 byte] By [morpheus3230] at [2007-12-28]
# 1
Well, this was a case of self inflicted wounds...
For one, the whole .Core issue was because the default installation of Office does NOT include the .NET Offce programability, so a quick Add Features install fixed that.

The other issue with the SaveAs method was caused my the fact that I also had an installation of Office 2000 along with Office 2003. The reason behind that was that I didn't want to use late binding so I thought that I could use the 9.0 Library without consequences if I installed both versions on my system.....Not a good idea...

So all in all I am back up and running... with a few lessons learned

morpheus3230 at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2

Hi,

Thanks for answering your own question. I am facing the same problem as you and I was wandering what add features you installed to fix it. I'm using Office 2003.

cheers,

Chris

ones81 at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3
Hi, I have exactly problem when I converted my code to vs 2005.
So could you tell me what "quick Add Features" you are talking about? Do you have the link for it?

Thanks

d_gao at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4

If i remember this correctly, if you go to add/remove features from office and after you expand Excel, you should see .NET Programmability Support.

That is what I am talking about.

Hope it helps

morpheus3230 at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 5
Thank. That helps.

gao

d_gao at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 6

hi friends..am very very new to VS2005..n am facing the same problem as mentioned way above !! :(

myt get a nervous breakdown if not helped soon ;)

what am trying to do is save an xslx report(yes, am wrking in office 2007!!) to a path i specify as follows:

xlBook.SaveAs("C://ChevronDocs//test.xlsx", Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal,null,null,false,false,Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlShared,false,false,null,null);

n whoa !! i get error eror n error !! uff..

please help..(i have specified the default path in web.config file.

VidhiYadav at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...