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

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
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,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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