CorelDraw & VBA
Back to the Main Menu
VBA Introduction
Artistic Text
Paragraph Text
Finding & Changing Text
Master Layers
Opening Other Applications
User Interface
Event Programming
Storing User Data
Error Handling
Speeding Up CorelDraw
CQL
VBA Security
Dialog Boxes & Tools
 
Guide to CorelDraw VBA
The Automatic Creation of Paragraph Text


CreateParagraphText creates text of the appropriate font, size, font style and position very similar to Artistic Text.

The full nomenclature to create paragraph text is as follows.
CreateParagraphText(Left As Double,
    Top As Double,
    Right As Double,
    Bottom As Double,
    [Text As String],
    [LanguageID As cdrTextLanguage = cdrLanguageNone],
    [CharSet As cdrTextCharSet = cdrCharSetMixed],
    [Font As String],
    [Size As Single],
    [Bold As cdrTriState = cdrUndefined],
    [Italic As cdrTriState = cdrUndefined],
    [Underline As cdrFontLine = cdrMixedFontLine],
    [Alignment As cdrAlignment = cdrMixedAlignment]) As Shape

The only differences are the left and bottom set the text frame size whereas before they set the actual text size.
You also now set the top and right sides of the text frame.

Left, Top, Right and Bottom specify the size and position of the of the text frame in inches.
If Right is less than Left then the right side will be positioned at 2 x Left - Right
I do not know why.
If the Bottom is greater than Top then Bottom takes on the lower of the values and the Top the greater value.

Text the contents of the paragraph frame.

LanguageID is not normally changed from the default so leave this blank.

Charset like the language leave this blank.

Font is usually specified unless you want to use the default font in which case you leave blank.

Size is the font size in points. If you leave it blank it will be the default font size.

Bold specifies whether the text is bold or not.
This will accept 1 or 3 options cdrFalse, cdrTrue or cdrUndefined.
It will also accept True or False without the cdr prefix.
If you leave it blank the default is false.
Some fonts such as AvantGarde Md BT cannot be made bold. Attempting to make them bold does not cause an error.

TriState Constants Value Description
cdrFalse 0 Specifies False
cdrTrue -1 Specifies True
cdrUndefined -2 Specifies Undefined

Italic like Bold is tristate, it will except cdrFalse, cdrTrue or cdrUndefined.
If you leave it blank the default is false.
Some fonts such as AvantGarde Md BT cannot be made italic. Attempting to make them italic does not cause an error.

Underline can have 1 of 8 values or you can leave blank to accept the default No Under Line.
UnderLine Constants Value Description
cdrNoFontLine 0 Specifies no font line
cdrSingleThinFontLine 1 Specifies thin font line including under spaces
cdrSingleThinWordFontLine 2 Specifies thin font line only under words
cdrSingleThickFontLine 3 Specifies thick font line including under spaces
cdrSingleThickWordFontLine 4 Specifies thin font line only under words
cdrDoubleThinFontLine 5 Specifies double-thin font line including under spaces
cdrDoubleThinWordFontLine 6 Specifies double-thin font line only under words
cdrMixedFontLine 7 Specifies mixed font line. How does this work?

Alignment can have 1 or 7 positions. Leaving blank means left align in Western countries.
Alignment Constants Value Description
cdrNoAlignment 0 Specifies no alignment but in effect is the same as cdrLeftAlignment.
cdrLeftAlignment 1 Specifies the left side of the text plus approximately> 0.1 to 0.3mm to the right depending on the character and font. Why?
cdrRightAlignment 2 Specifies the right side of the text but is too far to the left. The distance to the left increases with font size.
If the text is italic the last character will be slightly too right.
cdrCenterAlignment 3 Specifies centre alignment
cdrFullJustifyAlignment 4 Left align text and full justification for mutiple lines of paragraph text.
cdrForceJustifyAlignment 5 Left align text and forces justification for mutiple lines of paragraph text.
cdrMixedAlignment 6 Specifies mixed alignment but in effect seems the same as cdrLeftAlignment


Here is a some sample code to create paragraph text.

    Dim shText as Shape
    Set shText = CorelDRAW.ActiveDocument.ActivePage.ActiveLayer.CreateParagraphText(30 / 25.4, 50 / 25.4, "Hello" & vbCr & "World", , , "Arial", 12, True, False, , cdrLeftAlignment)
    shText.LeftX = 30 / 25.4
    shText.Fill.UniformColor.CMYKAssign 0, 0, 0, 100
    Set shText = Nothing

The 1st line defines a variable shText as being a shape. The code reserves computer memory to store the properties of a shape.
You can use this variable to refer to the shape.

The 2nd line creates the paragraph text, shText, on the active layer of the active page.
If you want page 3 you could substitutePages(3).Layers(2) for .ActivePage.ActiveLayer
Use Layers(2) not Layers(1) as Layers(1) is the Guides layer.
The text is to be 30mm from the left edge of the page & the first line is 50mm from the bottom edge.
CorelDraw works in inches. If you work in millimetres, as I do, you must divide your millimetres by 25.4 to convert to inches for CorelDraw.
The text is Hello World with a carriage return between.
The vbCr represents a carriage return so there will be a second line of text containing the word World.
If the text was to be on one line the text would have been "Hello World".
Leave the LanguageID & CharSet as the default.
The font is Arial and its size is 12 point.
The text is to be Bold, not Italic and not UnderLined.
Alignment is left so that the left end of text will be approximately 30mm from the edge of the page.

The 3rd line is to accurately position the text.
Its a fault of CorelDraw but CreateParagraphText never places the text in the exact horizontal position requested.
Notice that the code requires inches so if using millimetres divide by 25.4 to convert to inches.
The start of line 2 could have been Set shText = CreateParagraphText(0, ....... to position the text at the page edge.
Line 3 would have still positioned the text 30mm from the edge.
If you want to position the right side of the text at 30mm use;
    shText.RightX = 30 / 25.4
If you want to position the centre of the text at 30mm use;
    shText.LeftX = 30 / 25.4 - (shText.SizeWidth)/2
The line above takes the centre of where the text should be and subtracts half of the width of the text.
The answer is where the left edge must be to place the centre in position at 30mm.

The 4th line is to fill the text with black color.
It is not necessary if you are happy with the default fill color.
For CMYK colors use;
Fill.UniformColor.CMYKAssign Cyan, Magenta, Yellow, Black
All 4 CMYK colors can vary from 0 to 100 inclusive.
Alternatively for RGB colors you would use;
Fill.UniformColor.RGBAssign Red, Green, Blue
All 3 RGB colors can vary from 0 to 255 inclusive.
Remember all color printers use CMYK and they should not print more than a total color of 300 for a dry toner printer.
ie Cyan + Magenta + Yellow + Black should not exceed 300.
Exceeding 300 can cause the dry toner to separate from the paper.

The 5th line is to avoid memory problems.
It releases the computer memory that stored the properties of shText so the memory becomes available for other uses.
For repetitive tasks this memory can build up and become a problem.
For every set you need at least one Set ....... = Nothing.
After this line you cannot use shText to refer to the shape again.


2017_08_31