How to use swCustProp.Add ?

I am trying to use macros to get, add, and delete custom properties. The code I have does not add a custom property. There is no error, it just doesn't add the custom property. The 'get' code does work.

Here is the macro code:

Option Explicit

Dim swApp As SldWorks.SldWorks

Dim swModel As ModelDoc2

Dim swModelDocExt As ModelDocExtension

Dim swCustProp As CustomPropertyManager

Dim val As String

Dim valout As String

Dim bool As Boolean

Dim swSelMgr            As SldWorks.SelectionMgr

Dim swFeat              As SldWorks.Feature

Dim swCustPropMgr       As SldWorks.CustomPropertyManager

Dim nRetVal             As Long

Dim vNameArr            As Variant

Dim vName               As Variant

Dim bRet                As Boolean

Dim TestPropVar        As String

Dim TestFieldName      As String

Dim TestFieldValue     As String

Sub main()

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set swModelDocExt = swModel.Extension

If swModel.GetType = swDocPART Then

    Set swCustProp = swModelDocExt.CustomPropertyManager("")

    'Get a Custom Property value

    bool = swCustProp.Get4("Part_Number", False, val, valout) 'This WORKS

     'Add a Custom Property

    TestPropVar = "TestVar"

    TestFieldName = "Test_Cust_Prop"

    TestFieldValue = "TestIT"

    bool = swCustProp.Add(TestFieldName, TestPropVar, TestFieldValue) 'This DOES NOT WORK

End If 'is part

End Sub

I appreciate any suggestions.

Don Michaels

Belcan Engineering, Solon Ohio

SolidworksApi macros