How to close a room not yet registered

Hello

 

I would like to make a:

ActiveWorkbook.Close

 

like we do for Excel!

 

 

The macro registration code gives:

 

Set swApp = Application.SldWorks

 

Set Part = swApp.ActiveDoc

Set Part = Nothing

swApp.CloseDoc "Part Name"

 

Except that not having registered it she has no definite name (except "Exhibit 1", Exhibit 2", Exhibit 3"......)

 

With:

swApp.ActiveDoc.Close I crashed solidworks (image attached)

 

 

thank you for your help!!


capture.png

Why not simply click on close ^^^or on the cross.....

 

I don't think a macro is necessary for this kind of manipulation.

4 Likes

Well, it's like opening a file, importing parts into an assembly or changing the material...

 

You can do it by hand, but if the program does it, you don't have to do it anymore.

 

I couldn't find this instruction anywhere on the forums...

I really don't see any point in closing the file without saving it

as a result, it can be lost in other files without the possibility of finding it easily

close without saving we lose everything?

@+ ;-)

 

2 Likes

I agree with Bart and Gt22

but if in your context it makes sense... look at QuitDoc Method (ISldWorks) instead  .

that closes without saving

 

 

6 Likes

At the same time, click on the macro icon, or click on a cross to close.

 

All in all, it comes down to the same thing, doesn't it?

 

Or I missed something....

 

 

In fact I do:

 

longstatus = Part.SaveAs3(link, 0, 2)

 

which saves my part in link except that I keep a part (copy) not saved in my Solidworks which is useless.

 

It's true that the source problem is: is it possible to save an open room and keep it displayed? (by VBA)

OK... it becomes more logical

so QuitDoc must work?

4 Likes

I don't understand the usefulness either. There is the close command for this, and what's more, in case of multiple documents open there is the close all command...

 

 

Saving a room by leaving it open as soon as possible?

 

CTRL+S ... No?

I agree with you on the usefulness of this action, but I am developing an application for a solidworks assistant who does not want to learn how to use the software...

 

Otherwise for those who are interested, there is: (Happydad's idea)

boolstatus = swApp.CloseAllDocuments(True)

 

but the window doesn't close, I think it's because of the request to save the part message that doesn't appear.

 

 

jfaradon

I have the impression that QuitDoc Method (ISldWorks) also asks for the name of the part before closing it.

 

 

thank you for your answers

I used the Sioux method to achieve this...  

 

For i = 1 To 30

swApp.CloseDoc "Part" & i
Next

 

You can also retrieve the name of the document and then activate it to close it:

 

myTitle = myModel.GetTitle

swApp.ActivateDoc2 myTitle, True, 0

swApp.QuitDoc myTitle

 

Because if you have more than 30 parts files, your solution won't work!