To save a variable when workbook is closed and reopened, BuiltinDocumentProperties can be used.
Code below is able to write code into Excel (checked via File/Info/Properties/Advanced Properties/Custom tab).
But can't seem to read custom variable using code below. Can read standard property such as "Author" though.
Code below is able to write code into Excel (checked via File/Info/Properties/Advanced Properties/Custom tab).
But can't seem to read custom variable using code below. Can read standard property such as "Author" though.
VBA Code:
Private Sub write_doc_property()
On Error Resume Next
my_saved_option = "Option 1"
With ActiveWorkbook.CustomDocumentProperties("my_property")
.Delete
End With
With ActiveWorkbook.CustomDocumentProperties
.Add Name:="my_property", _
LinkToContent:=False, _
Type:=msoPropertyTypeString, _
Value:=my_saved_option
End With
End Sub
Sub test()
Debug.Print ActiveWorkbook.BuiltinDocumentProperties("Author") 'This works, Author is a standard property
Debug.Print ActiveWorkbook.BuiltinDocumentProperties("my_property") 'Doesn't work
End Sub