ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Object libraries and different ones with different versions (https://www.excelbanter.com/excel-programming/325341-re-object-libraries-different-ones-different-versions.html)

HeatherO

Object libraries and different ones with different versions
 
I have created a macro in word and it references the excel 11.0 object
library. My problem is the person I created it for runs excel 2000 and only
has the 9.0 object library. So everytime they run it, it crashes. I did
look at the article on late binding but I am not sure if I understand it
correctly. If I do take away the reference library how will the macro
understand some of my vlookups and stuff that is specific to excel? Here is
a sample of my code:

Public AppXL As Excel.Application

Sub client_count(filename)
' Macro A
'open excel client listing table and count number of accounts.


Dim xlntrn As Boolean
Dim lislrow As Long
Dim lokval As Integer
Dim clcnt As Integer
Dim cnttxt As String


On Error Resume Next
Set AppXL = CreateObject("Excel.application")

If Err Then
xlntrn = True
Set AppXL = New Application
End If

clcnt = 0


AppXL.Workbooks.Open ("C:\Model Pilot\Model Grid_SWI.xls")
AppXL.Workbooks.Open ("C:\Model Pilot\Names.xls")
AppXL.Workbooks.Open (filename)


Workbooks(filename).worksheets("Sheet1").Activate
With ActiveSheet
'get the last row of data for the ranges.

lislrow = AppXL.Cells(Rows.Count, "A").End(xlUp).Row

'sort data by lastname account number in listing excel file

Range("A2:Y" & lislrow).Sort Key1:=Range("G2"), Order1:=xlAscending,
Key2:=Range _
("A2"), Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1,
MatchCase _
:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal

For counter = 2 To lislrow

If counter 2 Then
If AppXL.Cells(counter, 1).Value = AppXL.Cells(counter - 1,
1).Value Then
GoTo Label1
End If
End If

If AppXL.Cells(counter, 26).Value = "Y" Then
GoTo Label1
End If

'lookup value
lokval = AppXL.Cells(counter, 15).Value


'row AE - col L of star
res = AppXL.vlookup(lokval, Workbooks("Model
Grid_SWI.xls").Sheets("Sheet1").Range("A2:M55"), 12, False)
If IsError(res) Then
AppXL.Cells(counter, 31).Value = ""
Else:
AppXL.Cells(counter, 31).Value = res
End If

clcnt = clcnt + 1#

Label1:
Next counter
End With


From what I read (but don't think I fully understand) this is how to late
bind it???

Public AppXL as object

and then the rest of the code would be the same or for every excel
function I use would I have to create another definition for excel.cells and
excel.vlookup and stuff?

Sorry but I find it hard to understand when they are using outlook as an
example. I wish I could understand better about what is included in late
binding for excel or does it not reference any of the excel references?

Maybe excel can include all library references with newer versions like
9.0, 10.0 and 11.0 and have someway of referencing the correct one based on
the version of excel the person is running. Just something to think of for
the next upgrade in excel it would be a nice feature especially with macros.

Thanks for any help in advance.
Heather


All times are GMT +1. The time now is 10:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com