Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Run code based on version

I am aware of the application.version function and I can also use the
conditional compile using the #if #else #endif statements.

What I need to do though is determine the version at run time and then run
different code depending. The conditional code needs a const which I cant
set at run time.

The various code is used to close of certain functionality of the workbook
etc... and this varies between versions.

Thanks in advance


Anthony


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Run code based on version

The conditional compile will only distinguish betweem XL2000+ and XL97

#If VBA6 Then
s = Replace("AZ", "Z", "B")
#Else
s = Application.Substitute("AZ", "Z", "B")
#End If

You can trap Excel's version like this
xlVer = Val(Left$(Application.Version, 2))

If you want to call a Excel function that was say introduced in XP and will
fail in earlier versions, place the code in a dedicated module for later
version stuff that will never be called in earlier versions.

Alternatively, depending on what you are doing, you might be able to get
away with something like this -

Dim oRng as Object ' note as object not as Range

If xlVer = 9 then
oRng.some-XL-Func(arg's)
Else
oRng.some-XL-Func(extended later version arg's)
End if

above would be suitable with functions like Find and Sort

Regards,
Peter T

"Anthony" wrote in message
...
I am aware of the application.version function and I can also use the
conditional compile using the #if #else #endif statements.

What I need to do though is determine the version at run time and then run
different code depending. The conditional code needs a const which I cant
set at run time.

The various code is used to close of certain functionality of the workbook
etc... and this varies between versions.

Thanks in advance


Anthony




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Run code based on version

not sure what you're looking for, but maybe something like this. when the
workbook opens, it sets the public variable. then the main sub runs whichever
sub based on the version.

in this workbook module:

Private Sub Workbook_Open()
eVersion = Application.Version
End Sub

in a general module:

Public eVersion As Long

Sub test1()
MsgBox "this runs if excel 2003"
End Sub
Sub test2()
MsgBox "this runs if excel 2007"
End Sub

Sub main_sub()
If eVersion = 11 Then
test1
ElseIf eVersion = 12 Then
test2
End If
End Sub


--


Gary


"Anthony" wrote in message
...
I am aware of the application.version function and I can also use the
conditional compile using the #if #else #endif statements.

What I need to do though is determine the version at run time and then run
different code depending. The conditional code needs a const which I cant set
at run time.

The various code is used to close of certain functionality of the workbook
etc... and this varies between versions.

Thanks in advance


Anthony



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Run code based on version

thank you very much. will give it a go

regards

Anthony
"Peter T" <peter_t@discussions wrote in message
...
The conditional compile will only distinguish betweem XL2000+ and XL97

#If VBA6 Then
s = Replace("AZ", "Z", "B")
#Else
s = Application.Substitute("AZ", "Z", "B")
#End If

You can trap Excel's version like this
xlVer = Val(Left$(Application.Version, 2))

If you want to call a Excel function that was say introduced in XP and
will
fail in earlier versions, place the code in a dedicated module for later
version stuff that will never be called in earlier versions.

Alternatively, depending on what you are doing, you might be able to get
away with something like this -

Dim oRng as Object ' note as object not as Range

If xlVer = 9 then
oRng.some-XL-Func(arg's)
Else
oRng.some-XL-Func(extended later version arg's)
End if

above would be suitable with functions like Find and Sort

Regards,
Peter T

"Anthony" wrote in message
...
I am aware of the application.version function and I can also use the
conditional compile using the #if #else #endif statements.

What I need to do though is determine the version at run time and then
run
different code depending. The conditional code needs a const which I cant
set at run time.

The various code is used to close of certain functionality of the
workbook
etc... and this varies between versions.

Thanks in advance


Anthony






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Run code based on version

thank you , I m going to try the dedicated modules

Regards

Anthony

"Peter T" <peter_t@discussions wrote in message
...
The conditional compile will only distinguish betweem XL2000+ and XL97

#If VBA6 Then
s = Replace("AZ", "Z", "B")
#Else
s = Application.Substitute("AZ", "Z", "B")
#End If

You can trap Excel's version like this
xlVer = Val(Left$(Application.Version, 2))

If you want to call a Excel function that was say introduced in XP and
will
fail in earlier versions, place the code in a dedicated module for later
version stuff that will never be called in earlier versions.

Alternatively, depending on what you are doing, you might be able to get
away with something like this -

Dim oRng as Object ' note as object not as Range

If xlVer = 9 then
oRng.some-XL-Func(arg's)
Else
oRng.some-XL-Func(extended later version arg's)
End if

above would be suitable with functions like Find and Sort

Regards,
Peter T

"Anthony" wrote in message
...
I am aware of the application.version function and I can also use the
conditional compile using the #if #else #endif statements.

What I need to do though is determine the version at run time and then
run
different code depending. The conditional code needs a const which I cant
set at run time.

The various code is used to close of certain functionality of the
workbook
etc... and this varies between versions.

Thanks in advance


Anthony






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Code Recompilation with new version of COM Dll [email protected] Excel Programming 1 September 21st 05 02:43 AM
Conditional Compilation Based On Excel Version Josh Sale Excel Programming 4 September 13th 05 09:39 PM
Code Glitch from version to version Shawn Excel Programming 2 November 24th 04 02:45 AM
Code for Trial Version Sadik Excel Programming 2 January 26th 04 06:35 PM
How to find the version of Excel in code WayneM Excel Programming 2 September 23rd 03 10:02 PM


All times are GMT +1. The time now is 09:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"