![]() |
Compiling and Late Binding
Hi
in the few lines of code below which was from Dave Petersen and Joe U, the use of the Excel command ForceFullCalculation does not produce a standard compilation error (due to late binding apparently), whereas it would if it was just Thisworkbook.ForceFullCalculation If Val(Application.Version) 11 Then Set oWkBk = ThisWorkbook oWkBk.ForceFullCalculation = True Debug.Print "Running forced calculation" End If Can someone explain briefly WHY late binding applies in this area? Many thanks Tim |
Compiling and Late Binding
Just my thoughts -- could be completely wrong technically. But it satisfies my
curiosity <vbg. Excel knows all the properties and methods for ThisWorkbook just like it knows all the properties and methods for a Range object. But it has no idea what you're doing with a variable declared as an Object. So no matter what version you're using if you use ThisWorkbook, excel knows -- you can't fool it. But if you use the Object variable, excel doesn't know or care until the code actually runs. On 12/16/2011 05:02, Tim Childs wrote: Hi in the few lines of code below which was from Dave Petersen and Joe U, the use of the Excel command ForceFullCalculation does not produce a standard compilation error (due to late binding apparently), whereas it would if it was just Thisworkbook.ForceFullCalculation If Val(Application.Version) 11 Then Set oWkBk = ThisWorkbook oWkBk.ForceFullCalculation = True Debug.Print "Running forced calculation" End If Can someone explain briefly WHY late binding applies in this area? Many thanks Tim -- Dave Peterson |
Compiling and Late Binding
On 16/12/2011 11:02, Tim Childs wrote:
Hi in the few lines of code below which was from Dave Petersen and Joe U, the use of the Excel command ForceFullCalculation does not produce a standard compilation error (due to late binding apparently), whereas it would if it was just Thisworkbook.ForceFullCalculation If Val(Application.Version) 11 Then Set oWkBk = ThisWorkbook oWkBk.ForceFullCalculation = True Debug.Print "Running forced calculation" End If Can someone explain briefly WHY late binding applies in this area? Excel doesn't bother to check if the object oWkBk can execute the statement "ForceFullCalculation = True" until it reaches that line. Protected with this code you can insert completely invalid invocations of non-existent and fictitious methods of oWkBk eg. oWkBk.Zork Xyzzy = "Hello Sailor" It will give a runtime error 438 "Object doesn't support property of method" if you ever execute the line but not until. So it is quite a clever way to hide Version related incompatibilities from the compiler. I am pretty sure no versions of XL ever supported the Zork method. (a prehistoric text based adventure game) Regards, Martin Brown |
Compiling and Late Binding
Hi Martin and Dave
MANY thanks for those responses - interesting to hear what the experts get up to with overcoming version incompatibilities. best wishes Tim ("Qu: Upgrades - Progress isn't all what it's cracked up to be?"). "Martin Brown" wrote in message ... On 16/12/2011 11:02, Tim Childs wrote: Hi in the few lines of code below which was from Dave Petersen and Joe U, the use of the Excel command ForceFullCalculation does not produce a standard compilation error (due to late binding apparently), whereas it would if it was just Thisworkbook.ForceFullCalculation If Val(Application.Version) 11 Then Set oWkBk = ThisWorkbook oWkBk.ForceFullCalculation = True Debug.Print "Running forced calculation" End If Can someone explain briefly WHY late binding applies in this area? Excel doesn't bother to check if the object oWkBk can execute the statement "ForceFullCalculation = True" until it reaches that line. Protected with this code you can insert completely invalid invocations of non-existent and fictitious methods of oWkBk eg. oWkBk.Zork Xyzzy = "Hello Sailor" It will give a runtime error 438 "Object doesn't support property of method" if you ever execute the line but not until. So it is quite a clever way to hide Version related incompatibilities from the compiler. I am pretty sure no versions of XL ever supported the Zork method. (a prehistoric text based adventure game) Regards, Martin Brown |
All times are GMT +1. The time now is 06:16 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com