Excel还真可以命名Application级的变量:
'运行test1,设置一个变量为:人数,其值为:124
Sub test1()
SetName "人数", 124
End Sub
Sub SetName(Name As String, Value) '命名变量,这是一个Application级的变量
Application.ExecuteExcel4Macro "SET.NAME(""" & Name & """," & Value & ")"
End Sub
'现在你可以关闭所有的工作簿,只留Application在运行。然后重新打开一个工作簿,运行test2
Function GetName(Name As String) '获取变量的值
GetName = Application.ExecuteExcel4Macro(Name)
End Function
Sub test2()
MsgBox GetName("人数")
End Sub
'运行test1,设置一个变量为:人数,其值为:124
Sub test1()
SetName "人数", 124
End Sub
Sub SetName(Name As String, Value) '命名变量,这是一个Application级的变量
Application.ExecuteExcel4Macro "SET.NAME(""" & Name & """," & Value & ")"
End Sub
'现在你可以关闭所有的工作簿,只留Application在运行。然后重新打开一个工作簿,运行test2
Function GetName(Name As String) '获取变量的值
GetName = Application.ExecuteExcel4Macro(Name)
End Function
Sub test2()
MsgBox GetName("人数")
End Sub