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
Try
OpenDoc.Save3(SwConst.swSaveAsOptions_e.swSaveAsOptions_SaveReferenced, 0,
0)Debug.WriteLine("Closing " & OpenDoc.GetPathName)
swApp.CloseDoc(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