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


Finding & Changing Text


Suppose you wish to change some text that is on every page.
It may be the page number and you wish to change the font, its size, position, add the words "Page " before the number etc.
It could be a word within the text that has to change such as replacing "meeting" with the word "conference".

All text and graphics on a CorelDraw page are shapes.
Shapes containing text are of the type cdrTextShape, so you need to check a shape and identify if it is of the type cdrTextShape.

Other properties of the shape can be useful.
Such properties are the position of the shape, the height & width.
The text within the shape may always contain only a number or start with the word "Page " or contain only 1 word or the font may be unique.

Sequentially check each page and test each shape on a page to find the targeted text shape.
Once the text shape is found make your change and then repeat on each page until all pages have been examined.

The following example is designed to find text at the foot of a page, in particular the page numbering.
It checks every page for a text shape whose left side is greater than 2" but less than 4". Its top is between 0.5" and 2".

Sub FindText()
     Dim pgPage As Page
     Dim shText As Shape

     For Each pgPage In ThisDocument.Pages
             For Each shText In pgPage.Shapes
                'Check that the shape is text and is within the area that you specify.
                'Measurements are in inches.
                If shText.Type = cdrTextShape And shText.LeftX > 2 And shText.LeftX < 4 And shText.TopY > 0.5 And shText.TopY < 2 Then
                    'Place you code here to change the text.
                    'eg If you want the next line adds the word "Page " in front of the existing page number.
                    'shText.Text.Story.Text = "Page " & shText.Text.Story.Text
                    MsgBox shText.Text.Story.Text
                End If
            Next shText
     Next pgPage
End Sub

2017_08_31