Dealing with symbols via VBA / macros

Hi folks,

In my work we make use of a fair number of symbol objects.  Once we've completed a design we create production-ready artwork where the symbols need to be converted to regular shapes.

The problem I'm having is that when I try to do this with my script (below) in Coreldraw X8 I'm definitely not getting the desired result.

With my sample script I would create a symbol made up of 3 random rectangles.  I would select the symbol and run the script.

What I expect to happen is that the script would duplicate the selected items, moving it over 20 units (to preserve the original artwork) and on the duplicate item would revert all symbols to shapes.

When I run the actual script I get weirdness that I can't pin down.  At first blush it looks like I have a symbol and a duplicate of shapes, but on closer examination that isn't all I have.

The duplicate shape instead consists of 3 copies of the original symbol.  Two of the copies are all separate rectangles and the third shape is now part of the original symbol.

I'm stumped, so I'm hoping that someone else might have some feedback!

Sub ShaperangeWithSymbol()
    ' This will give a break-down of what happens to our ShapeRange when a symbol is converted to objects
        ' If there is no selection then we can stop the process right now
        
    Dim sr As ShapeRange
    Dim workRange As ShapeRange
    Dim symbolRange As ShapeRange
    Dim s As Shape
        
    ' Set the range from the current selection
    Set sr = ActiveSelectionRange.Shapes.FindShapes.All
    
    ' Make a copy so that we do not work on the original artwork
    Set workRange = sr.Duplicate(20).UngroupAllEx
    
    If (sr.count < 1) Then
        MsgBox ("Please select at least one shape.")
        Exit Sub
    End If

    ' Find all the symbols in our duplicate range and convert them to objects
    Set symbolRange = workRange.Shapes.FindShapes(Query:="@type = 'symbol'")
    
    For Each s In symbolRange
        If (s.Type = cdrSymbolShape) Then
            s.Symbol.RevertToShapes
        End If
    Next s
 
    
End Sub

Parents Reply Children
No Data