You are currently reviewing an older revision of this page.
An Example (Written for CorelDRAW X4. Steps may differ slightly for older versions)
Lets assume that a common task that you need perform is to make an object twice as big and move it to the left by 10 mm. If you don't already know VBA, a good place to start is to record a macro that performs the task.
You have now recorded a new macro. Lets try it out. With your rectangle selected, go to Tools>Macros>Run Macro. A "Run Macro" dialog will pop up. In the Macros in: drop down choose GlobalMacros. You shoud now see an item that says RecordedMacros.DoubleSizeAndMove (or whatever name you gave it). Select it and hit run.
We seem to have problem, It didn't change the rectangle. It is time to look at the code and see what happened. Press "Alt+F11" to bring up the macro editor.
In the project pane (left hand side), Expand GlobalMacros. Expand Modules. Double click RecordedMacros.
Sub DoubleSizeAndMove() ' Recorded 05/02/2009 Dim OrigSelection As ShapeRange Set OrigSelection = ActiveSelectionRange ActiveDocument.ReferencePoint = cdrCenter OrigSelection.SetSize 2.78822, 2.78822 OrigSelection.SetPosition 4.005394, 7.911705End Sub
This may look a little intimidating so we'll break it up.
"Dim OrigSelection As ShapeRange" This line declares a variable that will be used. A variable holds some data. For example, if you need to store a number or text. In this case we're storing a ShapeRange, which is really just a collection of shapes in the document.
"Set OrigSelection = ActiveSelectionRange" This line assigns the selected shapes to the variable we declared.
"ActiveDocument.ReferencePoint = cdrCenter" This tells VBA that all operations will be performed using the center of the object as the origin. In other words, if we scale the left and right side change by the same amount.
"OrigSelection.SetSize 2.78822, 2.78822" and "OrigSelection.SetPosition 4.005394, 7.911705" are the operation we're applying to the selection.
On closer inspection of the last two lines we see why our rectangle didn't change when we ran the macro the second time; The recorder set the size and position directly rather than multiplying the current size by 2 and moving the current position to the left by 1 inch. Since we had already set the rectangle size and position, running the macro was repeating the exact same size and position, so nothing changed. The Recorder is very good at doing exactly what we ask, but not very good at doing what we expect.What we need to do is modify the macro so that we first get the current size and position and modify them accordingly. But how do we do that? This is where VBA shines, you can often find a function you need by using the "Autocomplete" feature. Since there is a SetSize function, maybe there is a GetSize function too? Try this:
Insert a line after "ActiveDocument.ReferencePoint = cdrCenter" and type "OrigSelection." (type the period too). You should see this: