Sheet Custom Property – Get Sheet Custom Property
Retrieves the value of a custom property from the specified Excel.Worksheet.
The function iterates through the CustomProperties collection of the worksheet to locate the specified property by name. If found, its value is returned. If not found or an error occurs, an empty string is returned and the error is displayed using ShowMessageBox
VB
Public Function xlGetSheetCustomProperty(wsSheet As Worksheet,
PropertyName As String) As String
Dim szAttributeValue As String = String.Empty
Try
Dim customProperties As CustomProperties = wsSheet.CustomProperties
' Check property and return value
For Each Prop As CustomProperty In customProperties
If Prop.Name = PropertyName Then
szAttributeValue = Prop.Value.ToString
Exit For
End If
Next
Catch ex As Exception
ShowMessageBox($"Error: {ex.Message}")
End Try
Return szAttributeValue
End Function