Read stored variable in "BuiltinDocumentProperties"

Formula11

Active Member
Joined
Mar 1, 2005
Messages
468
Office Version
  1. 365
Platform
  1. Windows
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.

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
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Use the BuiltinDocumentProperties property to return the collection of built-in document properties.
Use for CustomDocumentProperties for custom document properties.
 
Upvote 0
Solution

Forum statistics

Threads
1,223,886
Messages
6,175,193
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top