ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
JGJOHN GEORGE26/02/2013

I am just trying to get the relative folder (current folder) of a file path with this macro but it doesn't show

Can someone please correct me to make it work?

I wanted to display only the last folder of the file path

'---------------------------------------

Option Explicit

Sub main()

    Dim swApp                       As SldWorks.SldWorks

    Dim swModel                     As SldWorks.ModelDoc2

    Dim swPart                      As SldWorks.PartDoc

    Dim bRet                        As Boolean

    Dim MyPath                      As String

    Dim MyFolder                    As String

   

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swPart = swModel

   

    MyFolder = CurDir$

   

    MyPath = Left(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") - 1)

   

    Debug.Print "File = " & swModel.GetPathName

    Debug.Print "Folder = " & MyPath

    Debug.Print "Current Folder = " & MyFolder

   

End Sub

'---------------------------------------