Trouble Working with Excel Versions

  • Thread starter Thread starter Michael Kellogg
  • Start date Start date
M

Michael Kellogg

My application works with Excel to put together spreadsheets for
reporting purposes. It runs just fine on my box, but when I put it on
another one, it bombs.

Here is the relevant code:

Public Function ImportSis(ByVal strSisFile As String) As Boolean
If m_Excel Is Nothing Then
m_Excel = New Excel.Application
End If
m_Excel.Visible = True
Dim oSis As Excel.Workbook
oSis = m_Excel.Workbooks.Open(strSisFile)

At that point, I get a NullReferenceException, saying that oSis hasn't
been instantiated. This method, though, returns a new reference so
instantiation should be irrelevant. For grins, I did a NEW right before
on the oSis, but got the same error.

This code runs just fine on my development box, running Excel 2003. It
also runs on another box that has Excel 2002. It bombs when on a box
running Excel 2000. I originally had used the reference for "Microsoft
Excel 11.0 Object Library" but when I suspected I had a versioning
problem I removed that reference, grabbed an "Excel09.olb" file off of
someone else's box running Office 2000, and made a reference to THAT
instead. That didn't solve my problem, though, and I just now took
another look at it and it somehow got back to the 11.0 version; weird.

Long story; anyone have any suggestions? How can I correctly reference
an Excel 2000 library instead, and do I need to worry about detecting the
version of Excel to load maybe a different version of the library at
runtime?

I appreciate any help.
 
This code works in office 2000 but not in 2003:

Dim oSis As Excel.Workbook = ExcelApplication.Workbooks.Add
oSis.Worksheets.Application.Cells(1, 1) = ...

I will be happy to know if there is a code that can work with both versions.
 
¤ My application works with Excel to put together spreadsheets for
¤ reporting purposes. It runs just fine on my box, but when I put it on
¤ another one, it bombs.
¤
¤ Here is the relevant code:
¤
¤ Public Function ImportSis(ByVal strSisFile As String) As Boolean
¤ If m_Excel Is Nothing Then
¤ m_Excel = New Excel.Application
¤ End If
¤ m_Excel.Visible = True
¤ Dim oSis As Excel.Workbook
¤ oSis = m_Excel.Workbooks.Open(strSisFile)
¤
¤ At that point, I get a NullReferenceException, saying that oSis hasn't
¤ been instantiated. This method, though, returns a new reference so
¤ instantiation should be irrelevant. For grins, I did a NEW right before
¤ on the oSis, but got the same error.
¤
¤ This code runs just fine on my development box, running Excel 2003. It
¤ also runs on another box that has Excel 2002. It bombs when on a box
¤ running Excel 2000. I originally had used the reference for "Microsoft
¤ Excel 11.0 Object Library" but when I suspected I had a versioning
¤ problem I removed that reference, grabbed an "Excel09.olb" file off of
¤ someone else's box running Office 2000, and made a reference to THAT
¤ instead. That didn't solve my problem, though, and I just now took
¤ another look at it and it somehow got back to the 11.0 version; weird.
¤
¤ Long story; anyone have any suggestions? How can I correctly reference
¤ an Excel 2000 library instead, and do I need to worry about detecting the
¤ version of Excel to load maybe a different version of the library at
¤ runtime?
¤
¤ I appreciate any help.

If you have to support multiple versions, use late binding.

How To Use Visual Basic .NET for Binding for Office Automation Servers
http://support.microsoft.com/default.aspx?scid=kb;en-us;304661

In addition, when developing your application you need to seriously consider working with the lowest
supported version of Office.


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Paul Clement said:
If you have to support multiple versions, use late binding.

How To Use Visual Basic .NET for Binding for Office Automation Servers
http://support.microsoft.com/default.aspx?scid=kb;en-us;304661

In addition, when developing your application you need to seriously
consider working with the lowest supported version of Office.

Excellent advice on both counts. I got roped into a higher version of
Excel on an earlier project which required XML features that only existed
in Excel 2003. But that application is only run by one person here, while
everyone else uses 2000.

Thanks for the help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top