Run code dependent on Excel version

Ludwig

Board Regular
Joined
Apr 7, 2003
Messages
97
Office Version
  1. 365
Platform
  1. Windows
I have a need to turn off ThisWorkbook.AutoSaveOn if it is on. Easily done, however if the user opens the workbook using 2013 or earlier, the VBAProject fails to compile. Perfectly understandable.

My question is ... is there a way to code the test in the VBA but "ignored" if not valid?

For example, being able to say (I know it won't work as shown) and have it compile and run on Excel 2013 & even earlier versions ..

Code:
If Val(Application.Version) > 15 then 
     if ThisWorkbook.AutoSaveOn then ThisWorkbook.AutoSaveOn = False"
end if

Is there a way to run a command in an equivalent manner to formula expression "Indirect("string")"?

Thanks for your help.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
If the default compile settings are in place then you can simply move the offending code to another sub and branch there if needed. VBA won't try to compile that sub as long as it isn't touched:
Code:
'Previous code
If Val(Application.Version) > 15 then 
    CheckAutosave
End If
'More code...

Sub CheckAutosave()
     if ThisWorkbook.AutoSaveOn then ThisWorkbook.AutoSaveOn = False
end Sub
 
Last edited:
Upvote 0
So simple!! Hadn't thought that VBA is compiled 'when used/called'. Many thanks, will do that now!
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,264
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top