Home/ Reference/ Connection & Init

win32com.client.Dispatch("CorelDRAW.Application.21")

Connect by version number; 21 is CorelDRAW 2019. If CDR is already running this attaches to that process, otherwise it starts a new one.

Signature

win32com.client.Dispatch("CorelDRAW.Application.21")

Notes

Connect by version number; 21 is CorelDRAW 2019. If CDR is already running this attaches to that process, otherwise it starts a new one.

Python example (runnable)

Requires pywin32. The example assumes app / doc / page / layer are already connected. See Connection & Init
Python
import win32com.client                 # COM client module

VER = 21                               # 21=2019  22=2020  23=2021  24=2022/2023  25=2024
app = win32com.client.Dispatch(f"CorelDRAW.Application.{VER}")
# app : root object; every other call hangs off it

print("Connected to CorelDRAW, version: ", app.Version)

What Dispatch actually does

Dispatch does not "start CorelDRAW". It takes a ProgID, asks the Windows COM registry for it, and gets back an object pointer through IDispatch. Once that is clear, most of the odd behaviour people hit becomes explainable:

The ProgID argument

The form is CorelDRAW.Application.<version>. The number is CorelDRAW's internal program version, not the release year — the two differ by a fixed offset. The commonly cited mapping:

Corel changed how versions are numbered from 2023 onward, and the tables floating around online frequently disagree. Do not guess — read the real value from the registry. Two keys matter:

If you omit the version, Dispatch("CorelDRAW.Application") resolves through CurVer. When several versions are installed and you must pin one, always write the full version — this is the single most common reason a script behaves differently on someone else's machine.

Return value

You get a dynamic dispatch object; every later call goes through IDispatch::Invoke. Three consequences: autocomplete is largely absent; whether a property reads or writes depends on whether it exposes propget / propput; and collection indices start at 1, not 0. That last one catches the most people.

Choosing between Dispatch, GetActiveObject and EnsureDispatch

Common errors and what they mean

Complete example

With initialisation, error handling and teardown. Note that it deliberately does not call app.Quit() — if you attached to an instance the user is working in, quitting closes their unsaved documents. The rule for that is at the end.

Python
import pythoncom
import win32com.client

def connect(progid="CorelDRAW.Application.21"):
    pythoncom.CoInitialize()          # optional on the main thread, required in workers
    try:
        app = win32com.client.Dispatch(progid)
    except pythoncom.com_error as e:
        hr, msg = e.args[0], e.args[1]
        if hr == -2147221005:
            raise SystemExit("No such ProgID: check the version, or read CurVer")
        if hr == -2147221164:
            raise SystemExit("Class not registered: Python/CorelDRAW bitness mismatch")
        raise
    app.Visible = True                # without this you drive an invisible window
    print("connected:", app.Version)
    return app

app = connect()
doc = app.ActiveDocument or app.CreateDocument()
print("document:", doc.Name, doc.Pages.Count, "pages")

Should you call Quit?

One question decides it: who started the instance.

Platform and version notes

All of this only holds on Windows. The macOS build of CorelDRAW has no COM and no equivalent scripting interface, so no win32com approach applies there — the only option is "export a file, process it outside".

About this section: Connection & Init

Connection & Init — connecting to CorelDRAW over COM.

Other entries in this section