CorelDraw X6 Macro to insert Date using DTPicker Control

I'm trying to insert a date into a label. I have written the following code. I can select a date by clicking on the arrow and the calendar pops up. The "CANCEL" button is working, but when I click "OK" I cannot get it to insert on the label. The label is a regular Corel document with text and images. I tried inserting a rectangle toolbox to see if I can get it to insert the date in there by using X,Y coordinates but that didn't work. I basically need to know how to insert DTPicker.Value onto the label.

I've tried this : 1. Add a button on macro form 2. Select the rectangle 3. Click the button 4. Macro will read X, Y Pos of the rectangle, then create text and positioning it on the center of the rectangle.

Please see my post on stackOverflow for more details: http://stackoverflow.com/questions/32389241/coreldraw-x6-macro-to-insert-date-using-dtpicker-control/32502426#32502426. Thank you. 

--------------------------

Private Sub OK_Click()

Dim sr As Shape

Set sr = ActivePage.SelectableShapes.FindShapes.All

CorelDRAW.ActiveDocument.ReferencePoint = cdrCenter

ActiveWindow.RulerOriginX = cdrCenter
ActiveWindow.RulerOriginY = cdrCenter

ActiveDocument.ActiveLayer.Selected = True
CorelDRAW.ActiveDocument.Unit = cdrInch
Set sh = CorelDRAW.ActiveLayer.CreateArtisticText(0, 0, CStr(DTPicker1.Value))

MsgBox sh
sh.PositionX = XPos
sh.PositionY = YPos

'Unload Me
End Sub

Parents
No Data
Reply
  • You have a couple problems with your code. First you will want to check that the DTPicker1.Value has a value or you could get and error as CreateArtisticText does not like an empty string.

    Second, you have a message box trying to display a shape. That is going to give you an Object doesn't support this property or method error. If you want the message box to display the text you would need to do this:

    MsgBox sh.Text.Story

    Also you are not setting XPos or YPos to any value, unless they are coming from another section of your code. Here is how I would do this:

    Private Sub OK_Click()
        Dim sr As ShapeRange
        Dim x As Double, y As Double
        Dim strMyDate As String
        Dim sDate As Shape
        
        'Set our ShapeRange to all the shapes on the active page
        Set sr = ActivePage.Shapes.All
        'Get the bottom left position of the ShapeRange
        sr.GetPositionEx cdrBottomLeft, x, y
        
        'Get the date from the DatePicker
        strMyDate = DatePicker1.Value
        
        'Check to make sure the string is not empty, CreateArtisticText does not like an empty string
        If strMyDate <> "" Then
            'Create the text with the date at the bottom left corner of the ShapeRange
            Set sDate = ActiveLayer.CreateArtisticText(x, y, strMyDate)
            
            'Move the text the distance of the height
            sDate.Move 0, -sDate.SizeHeight
        End If
    End Sub
    

    As you can see, I select all the shapes on the page, get the bottom left position of them and then create some artistic text with your date value. I then move the text down the height of the text so that it is not running into any of the shapes.

    Hopefully that helps. Just as a word of caution I would stay away from using the DatePicker if you are going to distribute your code. In general you need Office to make sure that it is installed on your machine and it is 32-bit only. So anyone using the 64-bit version of CorelDRAW X6 is not going to be able to use it. 

    I recently completed a project that needed several dates and I decided to use a custom docker with jQuery and jQuery UI, you can see the Date Picker in action below. 

    -Shelby

Children