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: Open the Immediate window.
'
' Postconditions:
' 1. The File to Attach dialog is displayed
and the file
' types
specified in the filter are listed.
' 2. Examine the Immediate window to verify that the
' name of the file you selected matches what
the name
' of the printed to the Immediate window.
'
'----------------------------------------------------------
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)
Debug.Print fileName
End Sub