Wend Without While

Hi, i'm getting a "wend without while" in this line of code:

   While Not swFeat Is Nothing

  

    If Espessura Is Nothing Then

   

        If swFeat.GetTypeName = "SheetMetal" Then

       

            Set swsheetmetal = swFeat.GetDefinition

            Thickness = swsheetmetal.Thickness

            conv = 1000

            Thickness = Thickness * conv

                Espessura = Thickness

                    AddCustProp swChildModel

                    AddCorte swChildModel

                   

        Debug.Print " Thickness is :"; Thickness; "milimeters"

       

        End If

       

            Set swFeat = swFeat.GetNextFeature

    Wend

But it's CLEARYL right there, why is this happening? The full code is:

Public Sub Exporting()

   Dim SwApp                       As SldWorks.SldWorks

   Dim SwModel                     As SldWorks.ModelDoc2

   Dim swAssy                      As SldWorks.AssemblyDoc

   Dim swConf                      As SldWorks.Configuration

   Dim swRootComp                  As SldWorks.Component2

   Dim nStart                      As Single

  

   Dim bRet                        As Boolean

 

   Set SwApp = Application.SldWorks

   Set SwModel = SwApp.ActiveDoc

   Set swConf = SwModel.GetActiveConfiguration

   Set swRootComp = swConf.GetRootComponent3(True)

   

        If SavingPath <= "" Then GoTo Ending Else: GoTo Start:

Start:

   Debug.Print "File = " & SwModel.GetPathName

  

   TraverseComponent swRootComp, 1

 

   Debug.Print "Finished!"

  

  

Ending:

End Sub

Sub TraverseComponent(swComp As SldWorks.Component2, nLevel As Long)

Dim vChildComp                  As Variant

   Dim SwApp                       As SldWorks.SldWorks

   Dim swPart                      As SldWorks.PartDoc

   Dim swAssy                      As SldWorks.AssemblyDoc

   Dim swChildComp                 As SldWorks.Component2

   Dim swConfig                    As SldWorks.Configuration

   Dim swConfMgr                   As SldWorks.ConfigurationManager

   Dim swChildModel                As SldWorks.ModelDoc2

   Dim SwModel                     As SldWorks.ModelDoc2

   Dim swChildCustPropMngr         As CustomPropertyManager

   Dim swChildModelDocExt          As ModelDocExtension

   Dim swsheetmetal                As SldWorks.SheetMetalFeatureData

   Dim swFeat                      As SldWorks.Feature

   Dim swBody                      As SldWorks.Body2

  

   Dim Sheet_metal                 As Boolean

   Dim Boolstatus                  As Boolean

  

   Dim Thickness                   As Double

   Dim conv                        As Double

  

   Dim i                           As Long

   Dim loptions                    As Long

   Dim lerrors                     As Long

  

   Dim sPadStr                     As String

   Dim FilePath                    As String

   Dim FileName                    As String

   Dim swThkDir                    As String

   Dim swMatDir                    As String

   Dim swCurrent                   As String

   Dim RefCfg                      As String

   Dim ChildConfigName             As String

   Dim sMatName                    As String

   Dim sMatDB                      As String

   Dim exFileName                  As String

   Dim Bodies                      As Variant

   Dim Extension                   As Variant

  

Set SwApp = Application.SldWorks

Set SwModel = SwApp.ActiveDoc

  

If Not SwModel Is Nothing Then

   

    If SwModel.GetType = swDocASSEMBLY Then GoTo Assembly Else GoTo Part1

       

Else: GoTo Fim

End If

Part1:

Set swPart = SwModel

Set swChildModel = SwModel

GoTo Part2:

Assembly:

   vChildComp = swComp.GetChildren

   For i = 0 To UBound(vChildComp)

       Set swChildComp = vChildComp(i)

       'Check to see if current component is suppressed

      

       If swChildComp.IsSuppressed = False Then GoTo Active Else GoTo Skip

      

Active:

Set SwApp = Application.SldWorks

Set swChildModel = swChildComp.GetModelDoc2

   'Check to see if child component is an Assembly or part

   If (swChildModel.GetType <> swDocPART) Then GoTo Jump 'Skips Subassemby level

Set swPart = swChildModel 'Applies part commands for current component

swCurrent = swChildComp.ReferencedConfiguration 'Get current configuration of component

Part2:

Bodies = swPart.GetBodies2(swBodyType_e.swAllBodies, True)

Set swBody = Bodies(0)

   If swBody.IsSheetMetal = 0 Then 'If Body is not sheet metal

           GoTo Jump

   End If

   If swBody.IsSheetMetal = 1 Then 'If body is sheet metal

       Debug.Print "Processing component " & FileName & " as a sheet metal component"

       Debug.Print "Current Config is : "; swCurrent

       GoTo Process

   End If

Process:

'Get Part Material

Set swPart = swChildModel

sMatName = swPart.GetMaterialPropertyName2(swCurrent, sMatDB)

If sMatName = "" Then sMatName = "None"

Debug.Print "    Current material is : "; sMatName

'Get File Name

FileName = swChildModel.GetTitle

Debug.Print "File Name is : "; FileName

'Get File Path

sPathName = swPart.GetPathName

Debug.Print "File Path is : "; sPathName

'Get part Thickness

Set swFeat = swChildModel.FirstFeature

   While Not swFeat Is Nothing

  

    If Espessura Is Nothing Then

   

        If swFeat.GetTypeName = "SheetMetal" Then

       

            Set swsheetmetal = swFeat.GetDefinition

            Thickness = swsheetmetal.Thickness

            conv = 1000

            Thickness = Thickness * conv

                Espessura = Thickness

                    AddCustProp swChildModel

                    AddCorte swChildModel

                   

        Debug.Print " Thickness is :"; Thickness; "milimeters"

       

        End If

       

            Set swFeat = swFeat.GetNextFeature

    Wend

End If

swMatDir = SavingPath & "\\" & sMatName

Debug.Print swMatDir

If Dir(swMatDir, vbDirectory) = "" Then MkDir swMatDir

swThkDir = SavingPath & "\\" & sMatName & "\\" & Thickness & "mm"

Debug.Print swThkDir

If Dir(swThkDir, vbDirectory) = "" Then MkDir swThkDir

exFileName = SavingPath & "\\" & sMatName & "\\" & Thickness & "\\" & FileName

Debug.Print exFileName

Set swOpenModel = SwApp.ActivateDoc3(swChildModel.GetPathName, True, loptions, lerrors)

swChildModel.ExportToDWG2 exFileName & ".DXF", sPathName, swExportToDWG_ExportSheetMetal, True, 0, False, False, options, Null

SwApp.CloseDoc (swChildModel.GetPathName)

        

GoTo Jump

        

Skip:

   Debug.Print "Skipped"

Jump:

       TraverseComponent swChildComp, nLevel + 1

          Next i

Fim:

End Sub

SolidworksApi macros