API: Close all open documents

I had to close all the open documents in an application I was writing. I
ended up having to work this out, so thought I would share it. It's VB.NET,
but could be easily modified to work in a macro or VB6.
Private Function CloseAllOpenSWFiles()
'close all open docs
Dim OpenDocs As SldWorks.EnumDocuments2
Dim OpenDoc As SldWorks.ModelDoc2
OpenDocs = swApp.EnumDocuments2()
OpenDoc = swApp.ActiveDoc
While Not OpenDoc Is Nothing
OpenDoc.Save3(SwConst.swSaveAsOptions_e.swSaveAsOptions_SaveReferenced, 0,
Debug.WriteLine("Closing " & OpenDoc.GetPathName)
OpenDocs.Next(1, OpenDoc, 0)
Catch ex As Exception
'if errors out, then all documents have been closed
OpenDoc = Nothing
End Try
End While
End Function
Reply to
Evan T. Basalik
Loading thread data ...

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.