A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
For example:
Dim MyVar As String
MyVar = ActiveWorkbook.CustomDocumentProperties("YourName")
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I'm trying to save a variable in excel. I want this variable to stay even if I close excel.
I want to use :
Sub AddCustomDocumentProperties()
ActiveDocument.CustomDocumentProperties.Add Name:="YourName", LinkToContent:=False, Value:="Joe", Type:=msoPropertyTypeString
End Sub
To save this variable in a document's propriety. However, when I launch this program it says the variable "ActiveDocument" does not exist.
How to solve this problem? Or is it possible to save a variable differently.
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Answer accepted by question author
For example:
Dim MyVar As String
MyVar = ActiveWorkbook.CustomDocumentProperties("YourName")
Answer accepted by question author
ActiveDocument is for Microsoft Word. The equivalent for Microsoft Excel is ActiveWorkbook. So use
ActiveWorkbook.CustomDocumentProperties.Add Name:="YourName", LinkToContent:=False, Value:="Joe", Type:=msoPropertyTypeString
It doesn't work. It says invalid argument or procedure
This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
Comments have been turned off. Learn more
It works!
How can I set a variable as this property's value now?