问题
Is it possible to use one variable in Excel VBA across multiple workbooks? Without using Add-in approach? as mentioned in here.
For e.g I am saving Windows User name in var sysUser and want to use this variable in multiple workbooks, how can I do that?
Thanks and best regards
Ahmed
回答1:
http://www.cpearson.com/excel/trulyglobalvariables.htm
This link contains two great solutions to this problem. Be sure to drill down to the "hidden name" technique's link which is short and sweet.
Here's the crux of chip's hidden name solution
Application.executexcel4mAcro("SET.NAME(""test"",1)")
See the link for full details
回答2:
source
Public variables can be used in any procedures in the project. If a public variable is declared in a standard module or a class module, it can also be used in any projects that reference the project where the public variable is declared.
You would need public name as type
to be outside of any function
as well as noted here
来源:https://stackoverflow.com/questions/17780945/using-excel-vba-variable-for-multiple-workbooks