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
VBA Security
Guide to CorelDraw VBA

Storing User Data

There are times when you want the user to provide the default locations of folders and files that your code may need. Other times the the code may place a shape in a particular position but the user finds this is never quite right for their job so they want to change the default position. They may want to change many other defaults such color, font type, size etc.

You have several options.
1. You could allow them to enter the new data within your code but they may make a mistake and they can find this area confusing.
2. Have a text file that they can change and your code reads.
    This means you issue both a cdr file and txt file and the txt file is located in a known location. It is slightly messy.
3. Create another page in the CorelDraw file and on this page are stored the variable values that the user can read and change.
    Your code can then read the data on this page.
    CorelDraw can have a table on the page and this can be read a bit like reading an Excel spreadsheet.
    You can even set the new page as UnPrintable so that the whole document can be printed but without the data page.
4. Store data in the Meta Data an area where author, Last Modified is stored.
5. An alternative is to store the data in an area called Object Data. Here objects are asssigned data.
    This area is usually used to store an objects data such as color, weight, size etc.
    It could be used to store data totally unrelated to the object that it is attached to.
    It is not an ideal solution.
6. A good solution is to use CorelDraw's own database, called Properties, within each CorelDraw file.
    These are used to store custom data with a document. They are only created and accessed via VBA.

        With ActiveDocument
                'Properties are addressed by a string and a long variable.
                'In this example 3 properties called "TestData", 1, "TestData", 2 and "TestData", 3 are created
                .Properties("TestData", 1) = "Hello" ' String
                .Properties("TestData", 2) = 1 ' Integer
                .Properties("TestData", 3) = 4/3 ' Double
                'Now read each data item.
                MsgBox .Properties("TestData", 1)
                MsgBox .Properties("TestData", 2)
                MsgBox .Properties("TestData", 3)
        End With

    To Delete Properties.
    ActiveDocument.Properties.DeleteByIndex (2)
    ActiveDocument.Properties.Delete "TestData", 2

    'To delete all properties of type TestDataA.
    ActiveDocument.Properties.DeleteAll "TestDataA"

I do not know of a way to hide graphics so that the user cannot find and delete them unless they are in another CorelDraw file that is zipped with a password. Excel has a method of hiding a worksheet called xlVeryHidden that hides a worksheet via VBA and it cannot be made visible again except via VBA. It is a pity CorelDraw does not have something similar.

Issued 2017_08_31