in

connecting users of the CorelDRAW family of products

Macro/Script Request

Last post 09-19-2008 11:40 by epicor. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 09-18-2008 8:13

    Macro/Script Request

    Anyone know of a script or macro that can read text in Draw and add the values?  So say I write 50 on one side of the sheet and 50 on the other, is there any way a macro/script could find them on the page, add them together and return 100?  It would be used for adding the values set within icons, usually 50+ icons at a time.

     

    Any help would be greatly appreciated. 

    Filed under: , ,
  • 09-19-2008 9:31 In reply to

    Re: Macro/Script Request

    This macro will add all numbers on a line, it will cause an error if there are any non numbers in the text.

    Public Sub addlines()
        Dim i As Integer
        Dim j As Integer
        Dim d As Double
        Dim tr As TextRange
        Dim words As TextRange
           
        If ActiveDocument.SelectionInfo.IsParagraphTextSelected Or ActiveDocument.SelectionInfo.IsArtisticTextSelected Then
            ActiveDocument.BeginCommandGroup "Add numbers"
           
            For i = 1 To ActiveShape.Text.Story.Lines.Count
                Set tr = ActiveShape.Text.Story.Lines.Item(i)
                d = 0
                For j = 1 To tr.words.Count
                    Set words = tr.words.Item(j)
                    d = d + words.Text
                Next j
                tr.Text = d & vbNewLine
            Next i
           
            ActiveDocument.EndCommandGroup
        End If
    End Sub

  • 09-19-2008 10:54 In reply to

    Re: Macro/Script Request

     Henrik you beast you! thanks man!!

  • 09-19-2008 11:40 In reply to

    Re: Macro/Script Request

    Ok, so i got it put into a little macro window with a text field for the answer, but it is creating copies of whatever text is selected.

     

    For example i typed 12, then 3, then 2 as seperate items.  i selected them all and ran the macro.  when i hit the calculate button it gives me just the first item in the series (i have it set to show d after the IF statement finishes), but it also copies it in the drawing!  So if i have just 12 selected it will act like i selected the 12, hit enter and typed 12 again. 

    If i use them as the same item (12 3 2) i get the answer 17 in the d field, but it also changes the text to 17 and adds another line of 17 underneath that.  haha.

    any help?

     

    EDIT:  Fixed - just got rid of the tr.Text = d & vbNewLine line.  Now i just have to make it work on a selection of icons with the text as part of the group haha.  Any help appreciated.

Page 1 of 1 (4 items)
© 2008 Corel Corporation. The content herein is in the form of a personal web log ("Blog") or forum posting. As such, the views expressed in this site are those of the participants and do not necessarily reflect the views of Corel Corporation, or its affiliates and their respective officers, directors, employees and agents. Terms and Conditions.