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
本文介绍如何在Excel中使用Application级变量和宏来简化操作流程,通过设置和获取变量,实现自动化处理,提升工作效率。
3135

被折叠的 条评论
为什么被折叠?



