Open "save as" macro dialog

Hello

I have a macro in Excel that opens parts in Solidworks from the links of the parts in my Excel file. This macro also changes dimensions in sketches.

I want to display the "Save As" dialog box so that the user can choose a name and location for the files that have been edited.

I have the following code that works in Solidworks but it doesn't work when I paste it into Excel:

Sub main()

Set swApp = _
Application.SldWorks
Set swModel = swApp.ActiveDoc
swModel.Extension.RunCommand swCommands_SaveAs, Empty
End Sub

 

Who knows the solution?

Thank you.

 

Hello

It's not as simple as copying and pasting code from SolidWorks to Excel!

Is there SolidWorks reference checked in the Visual Basic option menu in Excel?

There are many references available containing "Solidworks".

Only "SldWorks 2012 Type Library" is checked.

I don't think it comes from there since my macro executes many actions on Solidworks from Excel without issue.

As for copy and paste, I haven't found what to change to switch from one software to another and that's why I tried this method.

Hello, can I ask what is the final goal of the operation?

In my excel file I have a table with the different values for the dimensions of the sketches according to the configurations.

The macro modifies the parts based on the Excel file. So I want to save the new part under a new name and in a user-chosen location.

 

PS: I don't use a part family here because, after testing, many bugs appear because of the too high number of configurations (about 2000).

Ok, I advise you to take a look at a technology called DriveWorks then.

DriveWorks is a specialist in SOLIDWORKS design automation.

We offer three versions, DriveWorksXpress, DriveWorks Solo and DriveWorks Pro.

DriveWorksXpress is already installed in your version of SOLIDWORKS and is completely free.

Solo and Pro offer many more automation features, of course.

http://www.driveworks.co.uk/products/driveworksxpress/ gives you an overview of Xpress (take a look at the different tabs (Feature, Benefit, Compare).

http://www.driveworks.co.uk/products/driveworksxpress/sample-projects/ Examples you can try yourself.

And a little video: https://www.youtube.com/watch?v=WCSO0mKsoxA

Finally, I would advise you to contact your SolidWorks reseller who can present the technology to you in more detail!

I can also answer your questions if you wish.

Thomas

1 Like

I don't want to go through DriveWorks because the macro already exists and is used regularly.

I would therefore like to develop it while maintaining the operations it already carries out.

The code given in the question finally works in Excel but does not perform the correct function. Indeed, it opens the "Open" window of Solidworks instead of the "Save As" window...

Hello

I think this code does what you want

Public Sub enregistrer_fichier()
    ' We get Solidworks back
    Set swApp = GetObject(, "SldWorks.Application")
    ' We retrieve the active document in solidworks
    Set swModel = swApp.ActiveDoc
    ' We open the registration dialog box
    swModel.Save
    ' We close the file
    swApp.CloseDoc swModel.GetTitle
End Sub

 

1 Like

Francis Onsenofu,

Thank you for your answer. The code works but doesn't correspond to what I wanted to get.

Indeed, it saves the modified file while I would like to save a copy in another directory and under another name in order to keep the base file without modification.

I tried to replace the swModel.Save with swModel.SaveAs but it doesn't work anymore.

I open the dialog box
so you can change the base name

To protect your base file maybe try to make it read-only
right-click on the file
property
Check the read-only box

For the saveas, you have to provide it with the recording path as well as the name of the file as an argument
I don't think you already know where it should be registered and under what name

In addition, the saveas will not open the registration dialog
from what I understand

but I could be wrong
;)

If I switch my files to read-only, the dialog box opens and I can edit all the data I need.

Thank you Francis Onsenfou !

1 Like