Excel Automation using VB.Net problem

dtrainer

New Member
Joined
May 26, 2010
Messages
4
Good Morning Everyone,
Ok, I have a problem with an application I wrote using Excel Automation. I am using Visual Studio 2008 and VB.Net. My development machine has both Excel 2003 and Excel 2007 installed. In my project references, I am referencing Microsoft.Office.Excel.Interop version 11.000 (2003). In the properties for the DLL reference, I have Copy Local set to true and Use Specific Version set to true. However, in the output window as the program runs, it clearly loads version 12.00(2007). Now, the spreadsheet is created without any errors. However, when I try to open the file using either version of Excel, I get the following message:
"The file you are trying to open "filename.xls" is in a different format than the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?"
In Excel 2007, you can open the file no problem. With Excel 2003, the file is unusable. The vast majority of our users still use earlier versions of excel so I really need to make this thing use the v11 dll's. What am I missing?

Thanks,
Don
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Actually, I am using the following code:

cmd.CommandText = ReportBaseQuery
DA.SelectCommand = cmd
DA.Fill(DS)
Result = WriteSingleSheetExcelFile(DS, FilePath)

The problem only arises when the user has both Excel 2003 and Excel 2007 loaded.
 
Upvote 0
OOps. Sorry. My bad. Thats the call to the function. The function itself uses the workbook.SaveAs method to save the file. I think I see now where I can use your example. I will let you know how it works out! Thanks a million!
 
Upvote 0
With a minor modification, that got me exactly what I wanted. I ALWAYS want the file saved in 2003 format so I just made the FileFormatNum = -4143 all the time and TaDaaa, the file can be opened in 2003 or 2007 no problem. Thanks for the help!
 
Upvote 0

Forum statistics

Threads
1,215,193
Messages
6,123,566
Members
449,108
Latest member
rache47

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top