Files
Open all SolidWorks parts in a folder
Code
'Demonstrates how to open all part documents in a specified folder
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
'Preconditions: make sure that have set the string variable "folder" to a directory _
with part files
'Results: parts in specified directory are opened
Dim swApp As SldWorks.SldWorks
Dim swDoc As ModelDoc2
Dim fileerror As Long
Dim filewarning As Long
Const folder As String = "C:\SolidWorks Training Files\Essentials\Lesson01\Case Study\"
Dim files As Variant
Sub main()
Set swApp = Application.SldWorks
files = Dir(folder & "*.sldprt", vbNormal)
Do While files <> ""
swApp.OpenDoc6 folder & files, swDocPART, 0, "", fileerror, filewarning
files = Dir
Loop
End Sub
'You must specify pathname the first time you call the Dir function, or an _
error occurs. If you also specify file attributes, pathname must be included.
'Dir returns the first file name that matches pathname. To get any additional _
file names that match pathname, call Dir again with no arguments. When no more _
file names match, Dir returns a zero-length string ("")