Community
hi
id like to know if i can check using msg box in vba, if a certain name in custom iproperties already exist.
thanks
Solved! Go to Solution.
Solved by jdkriek. Go to Solution.
Solved by jdkriek. Go to Solution.
This should do the trick:
Public Sub cPropCheck() Dim oDoc As Document Set oDoc = ThisApplication.ActiveDocument Dim customPropSet As PropertySet Set customPropSet = oDoc.PropertySets.Item( _ "Inventor User Defined Properties") Dim iProp As Property Dim sName As String ' Define name here sName = "MyCustomProp" For Each iProp In customPropSet If iProp.Name = sName Then MsgBox (sName & " already exists") End If Next iProp End Sub
If you want both status you will need to use a boolean and stop the loop:
Public Sub cPropCheck() Dim oDoc As Document Set oDoc = ThisApplication.ActiveDocument Dim customPropSet As PropertySet Set customPropSet = oDoc.PropertySets.Item( _ "Inventor User Defined Properties") Dim iProp As Property Dim sName As String ' Define name here sName = "MyCustomProp" Dim Status As Boolean Status = False For Each iProp In customPropSet If iProp.Name = sName Then Status = True 'Prop Exists Exit For 'Stop Loop End If Next iProp MsgBox (sName & " exists " & Status) End Sub