Introducing automation and VBA 3
Visual Basic for Applications, more commonly known as VBA, is a built-in programming language that can automate
repetitive functions and create intelligent solutions in CorelDRAW. Corel Graphics Suite 12 includes VBA version 6.3.
VBA is both a language and an editor. It is not possible to have the language without the editor, nor is it possible to edit
VBA in anything but the VB Editor. And the VB Editor is also needed to run VBA programs.
VBA is developed by Microsoft and is built into almost all of its desktop applications, including Microsoft® Office. VBA
is licensed by Microsoft to other companies, including Corel Corporation (in CorelDRAW, Corel PHOTO-PAINTâ, and
WordPerfectâ), Autodesk, Inc. (in AutoCADâ), IntelliCAD Technology Consortium (IntelliCAD®), and many others.
This enables CorelDRAW to communicate with a wide array of applications that support VBA. A complete list of
applications that support VBA can be viewed on the Microsoft Web site at
www.msdn.microsoft.com/vba/companies/company.asp.
It is not necessary for an application to support VBA for the VBA engine in CorelDRAW to control that application.
That means you can build solutions in CorelDRAW that access databases, word processors, specialized content editors,
XML documents, and more.
What is automation?
Most actions that you can do in CorelDRAW can be done programmatically through VBA. This programmability of
CorelDRAW is called automation. Automating repetitive tasks can save time and reduce effort, while automating
complex tasks can make possible the otherwise impossible.
In its simplest form, automation is simply recording a sequence of actions (a macro) in CorelDRAW, which can be played
back time and again. The term "macro" has come to include any code accessible to VBA running within the process,
even though some of that code might be far more advanced than a mere set of recorded actions. Thus wherever "macro"
is used in this guide, it refers to VBA functions and subroutines.
While it is possible to record a sequence of actions in CorelDRAW, the real power of automation and VBA is that these
recordings can be edited to provide conditional and looping execution. For example, a simple macro may set the selected
shape's fill color to red and apply a one-point outline. But, by adding a condition and looping to the VBA code, the
macro could, for example, be made to seek out each selected shape and apply only the fill to text shapes and the outline
to all other shape types.
VBA for non-programmers
Visual Basic for Applications (VBA) is based on Microsoft's successful Visual Basic (VB) programming language. The
main difference between VBA and VB is that you cannot create stand-alone executable (EXE) files using VBA, which
you can with full VB; you can only create programs in VBA that run inside the host application, in this case
CorelDRAW. In all other respects VBA and VB are the same.
Visual Basic is, as the name describes, a "visual" version of the BASIC language. This means that it is a very easy
language to learn, and it is helped in this by providing visual cues within the editor. Microsoft has added a great deal to
the original BASIC language, and it is now a powerful and fast language, although not as powerful as Java or C++, or
as quick as C.
The aim of this guide is not to teach you how to become a programmer –– you must do that on your own. The aim of
this guide is to teach experienced programmers how to apply their skills to developing useful solutions within
CorelDRAW. Before continuing reading this guide, you may find it useful to refer to the many books that have been
written about VBA and Visual Basic.
CorelDRAW Graphics Suite 12 Programming Guide for VBA 6