I need help with this macro. It is not successfully creating the custom property. Can anyone help?
' This SolidWorks VBA macro sets the "dn" custom property based on the
' first three characters after "DET-" in the file name of the open part.
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swCustPropMgr As CustomPropertyManager
Dim fileName As String
Dim dnValue As String
Dim detPos As Long
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If swModel Is Nothing Then
MsgBox "No active document!"
Exit Sub
End If
fileName = swModel.GetPathName
fileName = Mid(fileName, InStrRev(fileName, "\\") + 1)
detPos = InStr(fileName, "DET-")
If detPos = 0 Then
MsgBox "Pattern 'DET-' not found in file name."
Exit Sub
End If
dnValue = Mid(fileName, detPos + 4, 3)
Set swCustPropMgr = swModel.Extension.CustomPropertyManager("")
Call swCustPropMgr.Add3("dn", swCustomPropertyText, dnValue, swCustomPropertyReplaceValue)
MsgBox "Property 'dn' set to '" & dnValue & "'"
End Sub
