Well, if you want to SetOption('NoVarsInStrings','on') at the top of your UDF, that is easy enough and the function will return the previous state so you can undo it at the end. All you need to do is save the return for later processing.

In other words, if it was already 'on' when you set it at the top, you will just leave it that way else you will toggle it back off. Somehow I don't see where a UDF is needed to do that.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.