Using Excel VBA variable for multiple workbooks

我只是一个虾纸丫 提交于 2019-12-25 07:35:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!