Hi everyone,
I'm new to CorelDraw.
I have some old books created using CorelDraw and wanted to do some changes in all documents, so I spent many hours trying to figure out how to do it.
The process is:
- Open all .cdr files from a directory (open Document method)
- Do several changes (font change, color text, fit page etc.)
- Write .cdr in another directory
I managed to figure out how to do the processing, but I am wondering if there is a way to "hide" the document during processing, A lot of flashing goes on.
BR
To stop the flashing you want to use Optimization. The help file provides the following example:
Sub Optimize() Dim i As Long Dim x As Double, y As Double, r As Double Dim n As Long Dim num As Long Dim MaxX As Double, MaxY As Double, MaxR As Double MaxX = ActivePage.SizeWidth MaxY = ActivePage.SizeHeight MaxR = 1 num = ActivePalette.ColorCount Optimization = True For i = 1 To 100 x = Rnd() * MaxX y = Rnd() * MaxY r = Rnd() * MaxR n = CLng(Fix(Rnd() * num)) + 1 Set s = ActiveLayer.CreateEllipse2(x, y, r) s.Fill.ApplyUniformFill ActivePalette.Color(n) Next i Optimization = False ActiveWindow.Refresh End Sub
The problem with Optimization is that if your code hits an error and it does not get turned off you will see some interesting behavior, or should I say you will not see it. ;-)
The better way to do this it to make sure you add an error handler to always turn the optimization off. I have also added a message box that lets the user know there way an error.
Sub OptimizeBetter() Dim i As Long Dim x As Double, y As Double, r As Double Dim n As Long Dim num As Long Dim MaxX As Double, MaxY As Double, MaxR As Double MaxX = ActivePage.SizeWidth MaxY = ActivePage.SizeHeight MaxR = 1 num = ActivePalette.ColorCount On Error GoTo ErrHandler Optimization = True For i = 1 To 100 x = Rnd() * MaxX y = Rnd() * MaxY r = Rnd() * MaxR n = CLng(Fix(Rnd() * num)) + 1 Set s = ActiveLayer.CreateEllipse2(x, y, r) s.Fill.ApplyUniformFill ActivePalette.Color(n) Next i ExitSub: Optimization = False ActiveWindow.Refresh Exit Sub ErrHandler: MsgBox "There was an Error." Resume ExitSub End Sub
Happy coding,
-Shelby
Thank you so much, Shelby!
I really appreciate the extra code added for error handling.