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.