Macro that crashes SolidWorks

Hello

this morning, coming back from vacation, I was amazed to see when launching one of my macros, Solidworks crashed.

 

It's quite annoying, and by the way not the first time it happens (Hence the reason that I make backups as regularly as possible, but despite this the backup is a bit dated..) [I should point out that I tried on two stations, the same for both. (SW2013 Win7 64 pro)]

So I really don't understand, when I try to launch or edit the macro, SolidWorks generates an error report and it closes (And this every time.. so impossible to recover my code :/)

 

Unfortunately, I can't give you the macro, for privacy reasons.

 

So I don't know if you've ever dealt with it or if you have a solution that could allow me to recover my code (And why not avoid this..)

Hello

Why can't you get your code back? Are your .swp files deleted?

It will be difficult to help you without code. Try to give you the list of actions performed by your macro.

See you.

1 Like

The answer is simple

I can't open the .swp file at all (It exists .. but when I go to "Macro -> Run, or Edit" then solidWorks crashes and closes) So it's impossible to recover the code.

It's like the file is corrupted, but what could have caused this? I was on vacation and before I left the file worked very well.

 

So in my opinion it's not a problem with the code, but with the .swp file itself

Hello.

 

Did you try to make a copy of it (CTRL+c, CTRL+v) and open the copy?

It's a silly principle but sometimes it works

Duplicate

Yes I tried...

I also put the file on the network and I tested it on another PC, similar result

Hello

By chance, there were no updates to the computers while you were away? I always think of the famous update: http://www.mycadblog.fr/problemes-solidworks-rencontres-apres-la-mise-a-jour-de-microsoft/

2 Likes

Hello

Maybe it's the macro editor that has a problem.

Does creating a new macro work?

1 Like

Check if you have had any log updates since your last macro that was working and look at the date

If you can via windaude put yourself back in configuration to the last date where your macro was working

I think you will have solved your problem

See this link among others

http://www.leguide3d.com/profiles/blogs/alerte-technique-conflit-avec-la-mise-jour-windows-kb3072630

@+

Is only one file concerned?

Thank you for your answers,

No traces of this update installed.

 

Regarding the macro editor, I can open and edit other macros without any problem.

 

And I remember having this problem a while ago, when suddenly the macro didn't work anymore.

 

Regarding the restoration, I would be surprised if the info service agreed.

And yes it's currently the only file concerned, but as I said it's already happened to me once or twice before.

Hello

A solution that could work:

Open the macro in another version of SolidWorks to re-register it as .bas or .swp, and sometimes it works again on the other version.

4 Likes

Without seeing the macro or knowing how it works, it may be complicated to go further upstream.

 

On the other hand, maybe you have prerequisites that are not done? For example, on one of my excel macros, I ask for the sheets to be unlocked. If they are not locked, I have the whole thing bugging.

Or did you do an infinite loop without wanting to with an unplanned option?

 

What's stranger is the closure during editing.

Have you tried to open it with a text editor?

With the texture editor it works! (Well it's unreadable but the file opens).

It may come from the code, but I have my doubts, because the problem would have appeared while coding and I could always edit it.

Is there a risk when SolidWorks opens the macro that it corrupts it unintentionally? Because this would be a bug. (Because most of the macros that have never been a problem for me are read-only, but here as I was working on them it was not).

1 Like

Hello

We had the same problem at home...

The cause was the following: My colleague had added a folder with space which had caused the macro to crash.

To avoid this inconvenience on my side I always have the macro in a notebook, which allowed us to rewrite the macro and understand how it works.

So all I can tell you is that if the macro crashed during the operation of solidworks, even when restarting or copying it you have little risk of being able to reuse it experienced... We had to redo it all over again

Or maybe the idea of @.PL

But advise, always copy your macro into a word and print the sa can always save in these cases the :)
 

2 Likes

That's what I've been saying to myself since this morning @Centor. I have to save them as a text file somewhere quickly^^

 

hot all the same the story of the file with a space that crashes everything!

Thank you

Indeed I make backups, but there I hadn't had any problems for a while and I lost a few days of work.

 

Anyway, I gave the macro file to .PL, it will tell me if it opens on SW2015.

 

While waiting for his answer, I thank you in advance.

2 Likes

Hi all

Your macros weren't crashing and now Yes. It's a mess, even unfortunate!

SolidWorks and more broadly Windows do not inform you of the changes they make,

Your colleagues, due to lack of time, don't tell you the details of their updates of this and that.

Conclusion: your macros can only be reliable over time!

Two precautions to take in my opinion:

  - corruption of the file containing a macro>> it's rare but doing evolutionary archiving (evolutionary = n°

       in file names): request an Import from the "VBA" programming interface,

       regularly, or, when your macro has gained "weight". A copy paste in Word only gives

       text but why not (hack).

  - the macro has no error handling >> use at least the "On error goto" or "On error" instructions

        resume next" (click on a keyword in your macro [e.g. "error"], then press F1 to get more information about the

        local or online help).

An example of Excel macros with an embryonic error handling (words underlined):

Private Sub Workbook_BeforeClose(Cancel As Boolean)
  On Error GoTo ErrorProcessingTo be placed at the beginning of each procedure (event-based or not)
  'Systematically hide the "Settings" sheet
    Sheets("Parameters"). Visible = False
  'Return to the zoom of the "Small user manual" sheet as it was when opening the file.
    Sheets("A little instruction manual"). Activate
    Range("A1:AI111"). Select: ActiveWindow.Zoom = True: [A1]. Select
  'Return to the zoom of the sheet "EVAL_GLOBALE_EXPLO2015" as it was when opening the file.
    With Sheets("EVAL_GLOBALE_EXPLO2015")
      . Activate
      Range("A1:S30"). Select: ActiveWindow.Zoom = True: [B6]. Select
  'Return to the visualization as it was when opening the file.
      [CTRL1] = 1: VisualTeaching 'View all teachings.
      [CTRL2] = 1: VisualGroup' Visualize the first of the groups of students.
  'Force the "Input Enabled" mode as when opening a file.
      . Unprotect
      . Shapes("InputStatus"). TextFrame.Characters.Text = "Input Enabled": [InputStatus] = True
      . Protect
    End With
  'Automatically save the file before it is closed.
    ActiveWorkbook.Save
    Exit Sub
Treatment: Label
  Stop 'For verification
 'in case the leaves have changed their name for example,
 'just in case...
 'Error processing is not programmed here...
End Sub

If a line under On Error GoTo Error is "crappy", it causes an error when the macro is executed, then it stops at the "Stop" statement. This indicates an error, it is a first step.

A little trick to locate the "crappy" line> click on ()  step by step to launch the macro and make it unfold > a yellow trace indicates the line that is going to be executed. As soon as the error appears, the crappy line does not run and the process continues below the ErrorProcessing: label.

The minimum error handling is a 'Stop' (keyword) under ErrorHandling: . From there you can retrieve the error number and use it to process the error, to warn, to ....

 

Have a nice day.

 

 

1 Like

I managed to open it in SW 2014, I sent the file back.

If necessary I can copy-paste the code to redo the macro!

Very interesting @caronmaxime

Maybe it would be wiser to make a tutorial?

http://www.lynkoa.com/tutorial/create

Because unfortunately, the forum pages don't accept the form so we don't see what's underlined!