Question

I need to know is selected shape word art or not.

Shape has property "Type" (returns enum MsoShapeType). When I insert word art and check this property - it returns msoAutoShape instead of msoTextEffect (with AutoShapeType==msoShapeRectangle).

How can I check that spae is word art (not usual rectangle with textbox) ?

Thanks!

Was it helpful?

Solution

If you select either the overall smartart shape or click into text within the smartart shape or select one of the shapes within the smart art, ActiveWindow.Selection.ShapeRange(1) will return the smartart shape.

So

If ActiveWindow.Selection.ShapeRange(1).HasSmartArt Then
   Debug.Print "It's smart art"
End if

[edited] But as you've pointed out, this is for smartart, not word art. My error, sorry. There isn't a WordArt shape as such; it's more like any shape that has had WordArt formatting applied to the shape as a whole or to text within the shape. That'd include formatting like glow, reflection, shadow and so on, or could be one of the WordArt presets, pre-selected combinations of these different effects. I've added an example that'll help identify shapes or ranges of text within shape that have these presets applied. I don't see any simple way of checking for user-applied WordArt formats other than looking at each run and each text box for each of the various properties (glow, reflection etc) that might be applied. Unfortunately, there's no WordArtFormat = None to tell us we can ignore it. It's either going to be one of the presets or -2, which can mean any of several things.

Sub WordArtist()

    Dim oSh As Shape
    Dim oRng As TextRange2

    ' Has word art formatting been applied to
    ' entire shape?
    Set oSh = ActiveWindow.Selection.ShapeRange(1)
    Debug.Print oSh.TextFrame2.WordArtFormat

    ' Has it been applied to individual chunks of
    ' text within the shape
    For Each oRng In oSh.TextFrame2.TextRange.Runs
        Debug.Print oRng.Font.WordArtFormat
    Next

    ' Note:
    ' A result of -2 for the entire shape could mean
    '   - No text in the shape; not really word art
    '   - Mixed formatting
    '   - Text/shape has had glow/shadow/reflection etc applied
    '     rather than one of the preset WordArt selections

End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top