Here's a sample Python macro for CorelDRAW that creates a red box 2x2 cm in size, 2 cm from the top and 2 cm from the left:
Sub PythonMacro()
Dim Python As Object
Set Python = CreateObject("Python.Interpreter")
Python.Exec "from comtypes.client import CreateObject"
Python.Exec "from comtypes.gen import CorelDRAW_12_0 as CorelDRAW"
Python.Exec "corel = CreateObject('CorelDRAW.Application.12')"
Python.Exec "doc = corel.ActiveDocument"
Python.Exec "shape = doc.ActivePage.CreateRectangle(2, 2, 2 + 2, 2 + 2)"
Python.Exec "shape.Outline.Color = CorelDRAW.cdrColorRed"
Set Python = Nothing
End Sub
Note that this code uses the comtypes library to create a reference to the CorelDRAW Application object, and then creates a rectangle 2x2 cm in size, 2 cm from the top and 2 cm from the left on the active page of the active document. The outline color of the rectangle is set to red.
comtypes
After you have pasted this code into the VBA editor, you can save the macro and run it to create a red box in your CorelDRAW document.
Here's a native VBA macro for CorelDRAW that creates a red box 2x2 cm in size, 2 cm from the top and 2 cm from the left:
Sub NativeMacro() Dim doc As Document
Set doc = Application.ActiveDocument
Dim shape As Shape
Set shape = doc.ActivePage.CreateRectangle(2, 2, 4, 4) shape.Outline.Color = cdrColorRed
In this macro, the ActiveDocument property of the Application object is used to get a reference to the active document, and then a rectangle is created on the active page using the CreateRectangle method. The outline color of the rectangle is set to red using the cdrColorRed constant.
ActiveDocument
Application
CreateRectangle
cdrColorRed
You can paste this code into the VBA editor, save the macro, and run it to create a red box in your CorelDRAW document.
I can't think of a use case, might be interesting to see what sort of job it would do of translating a macro from a completely different program that was functionally a fit for Draw. Nothing too complex, maybe some bitmap effect.
Did you try running the VBA code that you posted?
Eskimo said:Did you try running the VBA code that you posted?
I've tried to open the Visual Studio Editor and get an immediate error. I think it is connected to me having VS 2022 installed. If I try to load the specific required editor that fails on install.
Couldn't see anything in Options to select the version of the editor installed.
Yani said:I've tried to open the Visual Studio Editor and get an immediate error.
You don't need to use the Visual Studio Editor to work with VBA in CorelDRAW.
If you have VBA support working correctly in CorelDRAW, then you should see a "Visual Basic for Applications" section in the Scripts docker.
That's where you should see your VBA projects and the macro subs associated with them. Right-click on a sub there, and you should have an option to edit it in the VBA editing environment.