Accessing custom property's value gives 'Out of Memory' error when value is null

With vbNullChar it works, sample:

Sub proptest()
  Dim sht As Worksheet
  Set sht = ThisWorkbook.Sheets("control")

  ' On Error Resume Next
  sht.CustomProperties.Item(1).Delete
  ' On Error GoTo 0

  Dim pathValue As Variant
  pathValue = vbNullChar

  Dim pathCustomProperty As CustomProperty
  Set pathCustomProperty = sht.CustomProperties.Add("path", pathValue)

  Dim cprop As CustomProperty
  For Each cprop In ThisWorkbook.Sheets("control").CustomProperties
      If cprop.Name = "path" Then
          Debug.Print cprop.Value
      End If
  Next

End Sub

Tags:

Excel

Vba