Hi Guys,
this tiny bit of code is driving me mad. keep running into a brick wall.
i am after a slice of iLogic code which will change the Active Standard Style to what ever i need.
i.e. my active Standard style is Default ISO but i also i have a Standard call Company XYZ (ISO) i want to be able to run an ilogic code to change the Active standard
Solved! Go to Solution.
Solved by iancross. Go to Solution.
i worked this out and it works just as i want
SyntaxEditor Code Snippet
Const kStandardName = "ABC" Const kObjDefaultsName = "My Defaults" Dim oDoc As DrawingDocument On Error Resume Next oDoc = ThisApplication.ActiveDocument Dim oStylesMgr As DrawingStylesManager oStylesMgr = oDoc.StylesManager Dim oStandard As DrawingStandardStyle oStandard = oStylesMgr.StandardStyles _ .Item(kStandardName) If oStandard Is Nothing Then oStandard = oStylesMgr.StandardStyles _ .Item(1).Copy(kStandardName) End If oStylesMgr.ActiveStandardStyle = oStandard
Hello,
You are using an On Error Resume Next in your code, I have some advice on that. With On Error Resume Next your telling your code that if something went wrong it has to ignore that line of code and go on with the next line. I suggest that If something went wrong you better handle that properly because it didn't went wrong without a reason, so handle errors and don't just ignore them.
It is also difficult to find errors in your code because the code executes each line and when your rule ends nothing happened and you end up searching for a long time about what went wrong. So please delete the On Error Resume Next line from your code and don't use this anymore.
If you assign values to an object it is best to start an If Then Else End If statement to determine if the object is not nothing. This way you avoid Errors because a object is not assigned and your code will go into the right direction. For debug purpose it is also simple to put MsgBox statements at strategic points in your code. With the On Error Resume Next statement the code will always excecute the next line and never reach your debug or control point.
To catch and handle errors it is best to use Try, Catch, End Try statements in your code. With this statement the code jumps to the Catch statement and there you can handle things.
Regards,
Eelco