MACRO LIBRARY

Display a SolidWorks-native Open dialog box

Free public access. No account or subscription required.

Files

Display a SolidWorks-native Open dialog box

Code

'Open file dialog box in SolidWorks
'Preconditions: SolidWorks is open
'Postconditions: After file is chosen and Open is clicked, file location is returned _
    as string
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
     
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim strFilter As String
Dim strFileName As String
Dim strFileConfig As String
Dim strFileDispName As String
Dim strFileOptions As Long
     
Sub main()
    Set swApp = Application.SldWorks
    strFilter = "SolidWorks Files (*.sldprt; *.sldasm; *.slddrw)|*.sldprt;*.sldasm;*.slddrw|All Files (*.*)|*.*|"
    strFileName = swApp.GetOpenFileName("Open file", "", strFilter, strFileOptions, strFileConfig, strFileDispName)
    Debug.Print strFileName
End Sub
    
'Notes:
'Filter format: "<label>|<extensions to filter>"
'<label> = Label as will appear in File As Type drop-down
'<extensions to filter> = *.sldprt;*.sldasm;*.slddrw
'For additional filters, put another | at the end and repeat the format:
'"<label-1>|<extensions to filter-1>|<label-2>|<extensions to filter-2>"