Open File Example (VBA)
This example shows how to prompt the user for the name of the file to
open. This example also shows how to set up filters by file types.
'---------------------------------------------------------
'
' Preconditions: None
'
' Postconditions: The File to Attach dialog is displayed
and the file
' types
specified in the filter are listed.
'
'----------------------------------------------------------
Option Explicit
Public swApp As
SldWorks.SldWorks
Public swModel As
SldWorks.ModelDoc2
Sub main()
Dim Filter As
String
Dim fileName As
String
Dim fileConfig As
String
Dim fileDispName As
String
Dim fileOptions As
Long
Set swApp = Application.SldWorks
' This following string has three filters associated with
it; note the use
' of the | character between filters
Filter = "SolidWorks Files (*.sldprt; *.sldasm; *.slddrw)|*.sldprt;*.sldasm;*.slddrw|Filter
name (*.fil)|*.fil|All Files (*.*)|*.*"
fileName = swApp.GetOpenFileName("File
to Attach", "", Filter, fileOptions, fileConfig, fileDispName)
' In the dialog, click the down-arrow associated with
Files to Type to see the
filters
' dialogFiles of Type down arrow key
Debug.Print fileName
End Sub