声明VBAvariables并在Excel的工作表中使用它

我想在Excel文档的vba代码中声明一个variables,并在单元格中使用它。

像这样的东西:

Vba代码:

Dim foo as Integer foo = 2 

Excel单元格(任何)

 =foo 

那可能吗?

您可以在代码模块中声明公用函数

 Public Function Foo() As Integer Foo = 2 End Function 

并在一个单元格中使用它

 =Foo()