Late Binding causes errors

funderburgh

Registered User.
Local time
Today, 16:24
Joined
Jun 25, 2008
Messages
118
I learned about late binding to an Excel object today when I tried to distribute my slick new version of the application I maintain to workstations with older versions of Excel.

Well I have late binding working (it seems) but I am getting errors on a couple of formatting statements that were working before: Here is a code example:

xlsheet.Range(xlsheet.Cells(HeadingRow, 1), xlsheet.Cells(HeadingRow, TargetCol)).HorizontalAlignment = xlCenter

' Bold The Column Titles/Change Fonts
xlsheet.Range(xlsheet.Cells(HeadingRow, 1), xlsheet.Cells(HeadingRow, TargetCol)).Font.Bold = True
xlsheet.Range(xlsheet.Cells(HeadingRow, 1), xlsheet.Cells(HeadingRow, TargetCol)).Font.Size = 11

I am getting a run-time error saying that the Horizontal Alignment can't be used with the Range. The formatting statements that follow (with the exact same Range syntax) work fine. I am getting the same result on SORT with Range.

So it's not the Range specifically, because I can change the font with the same syntax - I can't figure out what is different with Alignment and Sort. I really need the Sort.

Any ideas are welcome.
 
possibly things like this

xlCenter

assuming this a constant in the xl library, as you are no longer using the library you need to replace any constant with the actual value.

remove the reference to the library (I assume you have already), and compile - the compiler should pick up any constants that no longer exist.

you need option explicit set in the module, as otherwise xlcenter will be created as a variable, possibly/probably with the wrong value
 
You're beautiful, I don't care what anyone says.
 

Users who are viewing this thread

Back
Top Bottom