Excel Exception...only on one computer?[RESOLVED]
Hello. This code give me an error, but only on one computer. It works fine on other computers, except the Account Managers computer...fun huh? Maybe it is an Excel setting on her computer?
VB Code:
If sfd.ShowDialog = DialogResult.OK Then
strExcelFile = sfd.FileName
xlWBook.SaveAs(strExcelFile) 'LINE 1188
Else
Exit Sub
End If
Here is the error:
System.NullReferenceException: Object reference not set to an instance of an object.
at Excel.WorkbookClass.SaveAs(Object Filename, Object FileFormat, Object Password, Object WriteResPassword, Object ReadOnlyRecommended, Object CreateBackup, XlSaveAsAccessMode AccessMode, Object ConflictResolution, Object AddToMru, Object TextCodepage, Object TextVisualLayout, Object Local)
at AZShower.frmIncomeExcel.btnExportToExcel_Click(Object sender, EventArgs e) in C:\VB.NET\AZShower\Accounting\frmIncomeExcel.vb:line 1188
Thanks for your time!
Re: Excel Exception...only on one computer?
Looks like xlWBook is not set to an Excel workbook object when line 1188 is called. You need to check how and where xlWBook is set for this instance to find why the object is not being set.
Re: Excel Exception...only on one computer?
But I don't understand because it is only on ONE computer that it doesn't work. Wouldn't it be some setting in Excel then?
Re: Excel Exception...only on one computer?
Is everyone, including the Account Manager, running the same version of Excel?
Is this one computer a laptop? I've had issues between desktops and laptops before.
Re: Excel Exception...only on one computer?
Well, I kind of figured it out. It will run when using Office XP or Office 2003, but NOT Office 2000. Are there any plug-ins I can use? Or updates? Or what should I do?
Thanks for the idea of checking the version....
Re: Excel Exception...only on one computer?
Has anyone ever used this kind of automation on Office 2000? Or can you just not do it?
Re: Excel Exception...only on one computer?
Given what you wrote, I'm guessing that the application was developed with a reference set to the Excel 10.0 Object Library (aka Excel XP). The object libraries are (for the most part **) forward compatible but not backward compatible.
If this is the case, go through your code and change all your Excel object references from early binding to late binding. You'll get a slight performance penalty, but for most operations this isn't even noticable.
** Many developers use forward Excel object library compatibility without a hitch, but Microsoft has stated in ther migration whitepapers that early binding is preferred because there are a few forward compatibility issues.
Re: Excel Exception...only on one computer?
As said previously you need to reference an earlier version of Office (specifcally Office 2000 as that is the earliest version you app is running on). For some more information on doing that see here.
Specifically this portion:
The Office XP primary interop assemblies only work with Office XP. If you
want your program to be backwards compatable with Office 2000, you need to
create your own interop assemblies by referencing the Office 2000 libraries
in your project.
To do this, first install Office 2000 on your development machine (you can
do a side-by-side install with Office XP, except for Outlook, if you specify
a different destination directory during install.) Then, remove all the
references in your project(s) to the Office libraries. Finally, create a
new reference to the Office 2000 libraries -- e.g., for Microsoft Word 2000,
select Add References, select COM tab, and add a reference to the Microsoft
Word 9.0 Object Library. Visual Studio will create an interop assembly for
Word 2000/Office 2000.
The new Office 2000 interop assembly should be forward compatable with
Office XP and Office 2003
Hope this helps!
Re: Excel Exception...only on one computer?
Silly question here but..is Office 2000 installed onto the development machine?
Re: Excel Exception...only on one computer?
I just installed it and found the 9.0 object library. Thanks Bob! It works now!
Re: Excel Exception...only on one computer?[RESOLVED]