Macro "save"

Hello

It's very simple but I can't create a macro to save a document.

Simply save with the same^me name, in the same location.

Does anyone have the solution?

Thank you in advance.

maybe with "swSaveAsCurrentVersion"? but I don't know how to code. How do I integrate it into my macro?

Hello

from API Help

This example shows how to save a file.
'-----------------------------------------------------------------
' Preconditions:
' 1. Open a model.
' 2. Open the Immediate window.
'
' Postconditions:
' 1. Zooms to fit the model in the graphics area.
' 2. Saves the model.
' 3. Examine the graphics area and Immediate window.
'------------------------------------------------------------------
Option Explicit

    Dim swApp               As SldWorks.SldWorks
     Dim swModel             As SldWorks.ModelDoc2
     Dim boolstatus          As Boolean
     Dim lErrors             As Long
     Dim lWarnings           As Long

Sub main()

    Set swApp = Application.SldWorks
     Set swModel = swApp.ActiveDoc
     swApp.Visible = True
     

    ' Make a change
     swModel.ViewZoomtofit2
     

    boolstatus = swModel.Save3(swSaveAsOptions_Silent, lErrors, lWarnings)
     

    ' Errors
     Debug.Print ("Errors as defined in swFileSaveError_e: " & lErrors)
     

    ' Warnings
     Debug.Print ("Warnings as defined in swFileSaveWarning_e: " & lWarnings)

End Sub
            

 

1 Like

Ha I validated your answer too quickly: It doesn't work for me.

Compilation error.

Whereas: end of investigation.

I stupidly pasted the taxte in VBA

Hello

You have to copy everything except the first line which is not in commentary.

Which version of SW (code is valid from 2018)

I have SW 2015 (for now)

By searching on the net on the basis of your answer, I think I found the same one for 2015 (no difference with the naked eye...)

http://help.solidworks.com/2015/English/api/sldworksapi/Save_File_Example_VB.htm

yes, it works!

Thank you very much;)