Creating Excel File for Different Versions

Creating Excel File for Different Versions

mgorecki
Collaborator Collaborator
775 Views
4 Replies
Message 1 of 5

Creating Excel File for Different Versions

mgorecki
Collaborator
Collaborator

Hello,

My program will output to a new Excel file.  I have Microsoft 2013 and 2010 installed on my computer.  There are people in my company that only have 2010, so I need to be able to output to 2010.

In the references, I have added:

Microsoft Excel 14.0 Object Library

Microsoft Office 14.0 Object Library

(14.0 = version 2010)

In my code I have used "Object" instead of Excel.Workbook as I read in another forum I have to do that for this to work in older versions of Excel.

Dim xlApp As Object

Dim xlWkBook As Object

Dim xlWkSheet As Object

'Dim colorRange As Range - can't use it currently

'Open Excel application

xlApp = CreateObject("Excel.Application")

'Make sure excel is visible and add a new workbook

xlApp.Visible = True

xlWkBook = xlApp.Workbooks.Add

xlWkSheet = xlApp.ActiveSheet

 

The problem happens when the file is saved and I double pick the file to open it, it tells me that the file format and the extension don't match.  I pick "Yes" to open it anyway and it opens just fine.  Is there any way to get around this warning message?

 

Thanks,

Mark

 

0 Likes
Accepted solutions (1)
776 Views
4 Replies
Replies (4)
Message 2 of 5

arcticad
Advisor
Advisor

Check if the file is a xls or an xlsx. 

 

Rename the file to .zip and unzip the file. 

 

If you have a few files then it's an xls 

 

otherwise if there are multiple folders it's an xlsx file. 

 

xlsImage.jpg

 

---------------------------



(defun botsbuildbots() (botsbuildbots))
0 Likes
Message 3 of 5

mgorecki
Collaborator
Collaborator

ok, it looks like its an .xlsx.

0 Likes
Message 4 of 5

andrewpuller3811
Advisor
Advisor

Without the code, it seems like the problem is being caused by having the file name extension set as .xls when the file format is actually the new .xlsx type.

 

I would suggest changing the file extension you are passing to match the file format you are creating/saving as.



If a post provides a fix for your issue, click on "Accept as Solution" to help other users find solutions to problems they might have that are similar to yours.

Andrew Puller
Maitland, NSW, Australia
Windows 11
Intel core i7 11800 @ 2.30 GHz with 32GB Ram
Civil 3d 2023
0 Likes
Message 5 of 5

mgorecki
Collaborator
Collaborator
Accepted solution

Ok I tried something else today and it seems to be working.

Originally, in the References I used Microsoft Excel 14.0 Object Library (14 = 2010, 15= 2013) from the COM tab.

Ref_Excel_COM.jpg

 

I removed that and replaced it with Microsoft Office Interop Excel from the .Net tab.  

Ref_Excel_Net.jpg

 

I saved it and it ran just fine without format/extension issue.

0 Likes