Replacing reference of Excel 2003 to Excel 2010 in my VB6 project - excel

I have a VB6 application running for years. This application always reference Excel 2003 in the past for creating XLS files. Now we would like to use Excel 2010 in place of 2003. So I installed only Excel 2010 on a separate dev computer and load my vb6 project.
When running the app, I got the error where my 'Microsoft Excel 10.0 Object Library' is missing. This is true because only Excel 2010 is installed on this computer and no more Excel 2003.
The problem is that when I would like the correct reference, I didn't find any 'Microsoft Excel 14.0 Object Library' or something equivalent for replacing this reference.
Any suggestion?
Thanks.

Early bound reference are "bound" (excuse the pun) to cause a problem on applications being distributed to users with different Excel versions.
Using late binding and coding for the earliest version of Excel you are willing to support is the solution. For example, if you were supporting Excel 2000, your application would only use methods supported in Excel 2000.
However, if your code was late bound, you could use ambiguous method calls and detect the local version to determine which code to run.
Ex:
Dim excelVersion As Long
Dim xl As Object
' get a reference to Excel.Application maybe from AddinInstance_OnConnection()?
excelVersion = Val(xl.Version)
Select Case excelVersion
Case 11 ' Excel 2003
' Excel 2003-only methods here
' ex: xl.FileSearch
Case 12 ' Excel 2007
' Excel 2007-only methods here
Case 14 ' Excel 2010
' Excel 2010-only methods here
' ex: something with Slicers
End Select
Since the code is late bound (i.e. derived from Object), I can specify methods that are valid only in Excel 2010 and the code will still compile. If the code was early bound to Excel 2003, it wouldn't compile. At runtime I determine the version to decide which methods to use.
You might also consider compiling different versions of your application, if you are using Excel 2010-specific features. Only you would know if that is possible.
Also, and I thought of this after writing this answer, but can't you reference Excel 2010 in your app, and if it is installed on computers with earlier versions of Excel, won't the reference automatically adjust to whatever version of Excel is installed?

Related

Compatibility issues with 2013 excel spread sheet and 2010 excel

I have a vba program in excel in my computer (which is using 64bit). My friend can't have all the functions to work (hers is 32bit). What code can I add to make it compatible with the 32bit?
I want to share this excel sheet with many coworkers, so I need it to be compatible with 32bit.
I notice the error happens when calling the function in the worksheet_SelectionChange. I have a code that uses the Days() function.
m = Application.WorksheetFunction.Days(Date, myRange)
Thanks.

Macro created in Excel 2010, shows complile error on other users machines [duplicate]

I just upgraded to Office 2016, which most of my users haven't done, and I'm getting a new error when users try to run my scripts.
"Compile Error, can't find project or library"
I looked in the references and it looks like it's trying to reference the "Microsoft Word 16.0 Object Library" and it's missing on machines running Office 2013. I don't see the option to change my reference to a 2013 version, and I don't know how to give my users access to the 2016 reference without upgrading everyone (not an option right now).
This error is coming up on the first executable line of code
Set app = Range("A2")
You need to include the Excel 15.0 Object Library in order to use Excel.Range("A2") like that or use late binding as shown below:
Dim excelApp As object, r as object
Set excelApp = CreateObject("Excel.Application")
Set r = excelApp.Range("A2")
Office documents where the VBA project references Office apps will work on later Office versions too. When you open them on the later version, they will appear to reference that later version.
However if you save such file with a later Office version and then open it with the original Office version, you will have MISSING: references to any Office apps other that the one to which the file belongs.
That is, if you have an Excel file that references Excel and Word, resave it under Office 2016 and then open in Office 2013, the reference to Excel will be fine, but the reference to Word will be MISSING:.
To avoid this, either always save the file under the earliest Office version that you support, or completely remove the references to other Office apps and use late binding to call them.

Office 2016 -> 2013 "compile error, can't find project or library"

I just upgraded to Office 2016, which most of my users haven't done, and I'm getting a new error when users try to run my scripts.
"Compile Error, can't find project or library"
I looked in the references and it looks like it's trying to reference the "Microsoft Word 16.0 Object Library" and it's missing on machines running Office 2013. I don't see the option to change my reference to a 2013 version, and I don't know how to give my users access to the 2016 reference without upgrading everyone (not an option right now).
This error is coming up on the first executable line of code
Set app = Range("A2")
You need to include the Excel 15.0 Object Library in order to use Excel.Range("A2") like that or use late binding as shown below:
Dim excelApp As object, r as object
Set excelApp = CreateObject("Excel.Application")
Set r = excelApp.Range("A2")
Office documents where the VBA project references Office apps will work on later Office versions too. When you open them on the later version, they will appear to reference that later version.
However if you save such file with a later Office version and then open it with the original Office version, you will have MISSING: references to any Office apps other that the one to which the file belongs.
That is, if you have an Excel file that references Excel and Word, resave it under Office 2016 and then open in Office 2013, the reference to Excel will be fine, but the reference to Word will be MISSING:.
To avoid this, either always save the file under the earliest Office version that you support, or completely remove the references to other Office apps and use late binding to call them.

how to use a macro in excel

The question is there are 'n' different ppts and I want to put all the ppts in one single ppt. Condition is I should not use copy paste rather I should write a function in excel using macros to get it done. So how do I do this?
It looks like you need to automate PowerPoint from Excel. The How to automate PowerPoint by using Visual Basic in Office 2003, in Office XP Developer, and in Office 2000 Developer article describes all the required steps for getting the job done. Be aware, the reference number corresponds to the Office installed on your machine. For example:
Microsoft PowerPoint 15.0 Object Library
Stands for PowerPoint 2013 and etc.

Excel 2003 Spreadsheet Object Disappears in Excel 2007

I've inherited an old Excel 2003 application, and need to convert it so that it works in Excel 2007. The application makes use of a spreadsheet as a "popup" inside the application for doing volume calculations. In Excel 2003, this works as expected. In Excel 2007, VBA complains with an "Object Required" error.
Browsing through the Object Browser, Excel 2003 lists "VolSheet" as a Spreadsheet object. Excel 2007 can't find it at all. Excel 2007 does list "VolSheet" as a Shape if you loop through all shapes (ActiveSheet.Shapes), however.
My question is: Is there a way to force Excel 2007 to recognize VolSheet as a spreadsheet? Would I have to Dim it somewhere and find a way to convert the Shape reference to a spreadsheet? Can I trick Excel 2007 into recognizing that it does in fact already exist inside one of the Worksheets?
Seems like you need to update your install of OWC on the 2007 machine
Office Web Components version 11 initially did not support Office 2007, but was updated to add it in SP1. See Link and Link for a security patch.

Resources