API Help

Good Morning

I am in need of some API help.  I found this code on the web and I cannot get it to run properly.  It gives me errors in hte noted locations (Red text beleow)  I am also looking to make this code work on only the dimensions marked as inspection dimensions.

I am new to code writing in SolidWorks but do have some experience in other applications.

Any help anyony could offer would be greatly appreciated.  I have attached the macro.

I am currently running SolidWorks 2009 SP3.0

' By handleman
' Available at: http://www.eng-tips.com/viewthread.cfm?qid=193453&page=1swApp As SldWorks.SldWorks
Dim swDoc As SldWorks.ModelDoc2
Dim swDwg As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim swDispDim As SldWorks.DisplayDimension
Dim swDim As SldWorks.Dimension
Dim sCurSuffix As String
Dim nOpenParPos As Long
Dim nCloseParPos As Long
Dim vDimVal As Variant
Dim dInchVal As Double
Dim sInchString As String
Dim sNewSuffix As String
Const DUALFORMAT As String = "0.00"
Dim KillFlag As Integer
Dim sMsg As String
Dim sRefPfx As String
Dim nRefNum As Long

Dim


Sub AddDimRefNums()

Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc

If swDoc.GetType <> swDocDRAWING Then
    MsgBox "This macro only works for drawing files."
    Exit Sub
End If

sMsg = "This macro will add a text suffix of a dimension reference number " & _
        vbCrLf & "to all dimensions in this drawing." & vbCrLf & vbCrLf & _
        "To add or update dimension reference numbers inside ""[ ]"", choose ""Yes""" & vbCrLf & _
        "To remove all reference numbers, including the ""[ ]"", choose ""No""" & _
        vbCrLf & "To quit, choose ""Cancel"""
KillFlag = MsgBox(sMsg, vbYesNoCancel, "Dimension Reference Numbers")

If KillFlag = vbCancel Then
    Exit Sub
End If

sRefPfx = InputBox("Please enter the reference prefix")

Set swDwg = swDoc

nRefNum = 1

Set swView = swDwg.GetFirstView
While Not (swView Is Nothing)
    Set swDispDim = swView.GetFirstDisplayDimension5
    While Not swDispDim Is Nothing
        Set swDim = swDispDim.GetDimension
        sInchString = sRefPfx & nRefNum
        nRefNum = nRefNum + 1
        sCurSuffix = swDispDim.GetText(swDimensionTextSuffix)
        nOpenParPos = InStr(1, sCurSuffix, "[", vbTextCompare)
        nCloseParPos = InStr(1, sCurSuffix, "]", vbTextCompare)
        If (KillFlag = vbNo) And (nOpenParPos > 0) And (nCloseParPos > 0) Then
**          sNewSuffix = Left(sCurSuffix, nOpenParPos - 1)
            sNewSuffix = sNewSuffix & Right(sCurSuffix, Len(sCurSuffix) - nCloseParPos)
        ElseIf (nOpenParPos > 0) And (nCloseParPos > 0) Then
**          sNewSuffix = Left(sCurSuffix, nOpenParPos)
            sNewSuffix = sNewSuffix & sInchString
            sNewSuffix = sNewSuffix & Right(sCurSuffix, Len(sCurSuffix) - (nCloseParPos - 1))
        Else
            If KillFlag <> vbNo Then
                sNewSuffix = "[" & sInchString & "] " & sCurSuffix
            Else
                sNewSuffix = sCurSuffix
            End If
        End If
        swDispDim.SetText swDimensionTextSuffix, sNewSuffix
        Set swDispDim = swDispDim.GetNext5
    Wend
    Set swView = swView.GetNextView
Wend


End Sub

Thanks

Chris Tellers

SolidworksApi macros