View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
joeu2004[_2_] joeu2004[_2_] is offline
external usenet poster
 
Posts: 829
Default Compiling Error in Earlier Version of Excel

"Tim Childs" wrote:
it is Excel 2007 where I'll want it to work unfortunately:
that's what we have at work. will try it next week


Don't bother. I think Dave's suggestion is superior. It can be simplified
as follows:

Dim ws As Workbook
If Application.Version = 12 Then ' XL2007 or later
Set ws = ThisWorkbook
ws.forcefullcalculation = true
End If

If "ws" were replaced with ThisWorkbook, a compile-time error would result.

But with "ws", apparently VBA does late-binding even though "ws" is typed as
Workbook (!).

It might be more reliable to declare "ws" as Variant, just to be sure that
VBA cannot use "early" binding in some later version.

-----

Regarding my suggestion....

It bothers me that I cannot find any Microsoft documentation about VBA
compile-time constants like VBA6 and VBA7.

It also bothers me that in Excel 2010, VBA 7.0 has a copyright date of only
2010. If VBA 7.x had been implemented for Excel 2007, I would expect a list
of copyright dates that includes 2007 or earlier. That is needed according
to US copyright law in order to protect code (i.e. by seeking monetary legal
remedies) written before Excel 2010.

The point is: I suspect that VBA7 is False in Excel 2007. I cannot confirm
that now, however.


----- original message -----

"Tim Childs" wrote in message
...
Hi

thanks for that

it is Excel 2007 where I'll want it to work unfortunately: that's what we
have at work. will try it next week

Tim

"joeu2004" wrote in message
...
"Tim Childs" wrote:
This piece of code
ThisWorkbook.ForceFullCalculation = True
will work in Excel 2007 and above

Is there any way to mark the code so that it
will avoid the COMPILING error in earlier versions


#If VBA7 Then
ThisWorkbook.ForceFullCalculation = True
#End If

VBA7 is false (undefined) in Excel 2003 and true in Excel 2010. I don't
know about Excel 2007.