I am currently working on a project in which I need to save a few variables, that i can use on every opening of my workbook, without the need to set it up manually on startup.
To create a custom document property, I am using the example-code provided by Microsoft on their official website.
Question:
After setting up the properties, I am accessing them by opening an item(x)
. The number x
seems to depend on the alphabetical order of my property's name.
Is there a way to read and to work with a property, opening it by its name?
Sub InitializeCustomProperty()
Dim wksSheet1 As Worksheet
Set wksSheet1 = Application.ActiveSheet
' Add metadata to worksheet.
wksSheet1.CustomProperties.Add _
Name:="Computer 1", Value:="computername"
End Sub
Sub Add_My_Computer1()
' sets the value of my custom property (i"ve found out its Item(1) by outputting my properties
Dim sHostName2 As String
sHostName2 = Environ$("computername")
Worksheets(1).CustomProperties.Item(1).Value = sHostName2
End Sub