AnsweredAssumed Answered

Macro Question : To all open documents.

Question asked by Matt Jones on Jul 5, 2015
Latest reply on Jul 22, 2015 by Leon Wurr

Hey Guys, new to the forum here but have been using solidworks for 7 or 8 years now!


I have written a basic macro to Save As a PDF (into the folder the drawing is in) and then close the document without saving. I was wondering if I can get this macro to run on all open documents from within the macro, ie. I hit the button once and it runs through every open document saving as a pdf and then closing.


Any help would be greatly appreciated! (See my macro details below)





Dim swApp As SldWorks.SldWorks

Dim Part As SldWorks.ModelDoc2


Sub main()


Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc


Dim FilePath As String

Dim Pathsize As Long

Dim PathNoExtension As String

Dim NewFilePath As String


FilePath = Part.GetPathName

Pathsize = Strings.Len(FilePath)

PathNoExtension = Strings.Left(FilePath, Pathsize - 6)

NewFilePath = PathNoExtension & "pdf"


Part.SaveAs2 NewFilePath, 0, True, False


swApp.QuitDoc Part.GetTitle 'to disable auto close of doc add ' to start of this line


MsgBox "Saved" & NewFilePath 'to get rid of message box add ' to start of this line



End Sub