PowerPoint SendKeys behaviour with 2007 and SmartArt

I don't like using SendKeys but in this PowerPoint 2007 case there is no other choice AFAIK.

I am trying to turn the outlines off for the shapes within a SmartArt object after it's been inserted into a slide by the user.

Since 2007 doesn't support the SmartArt object model, I have to use GroupItems. But even then, the GroupItems properties are read only. So my fallback plan is to replicate the user behaviour by using SendKeys to tab through each shape in the SmartArt group and send the sequence to turn off the line.

I'm using the app event WindowSelectionChange(ByVal Sel As Selection) to detect the object insertion and then run a selection checking procedure (selection type / count / shape type etc.) before running this code to do the SmartArt formatting:

  ' Loop through each shape in the group and turn the outline off
  iShapes = ActiveWindow.Selection.ShapeRange(1).GroupItems.Count
  For counter = 1 To iShapes
    SendKeys ("{TAB}"), True  ' Tab
    SendKeys ("%"), True      ' Alt
    SendKeys ("JO"), True     ' Context sensitive Format tab
    SendKeys ("SO"), True     ' Shape Outline
    SendKeys ("N"), True      ' None

Open in new window

Now, if I manually run the above code via a test macro using Alt+F8 to run it when a SmartArt object is selected, the formatting changes are applied.

But when I run it programmatically as intended via the app event handler, it fails and the paragraph dialog box appears instead. The key sequence for that is Alt+H+PG.

I've also tried doing things before running the above code such as "refreshing" the slide by going to slide n+1 and then back, inserting DoEvents, waiting for a fews seconds and even interrupting the code with a msgbox. Nothing has worked.

How can I get SendKeys to work in this situation?
LVL 14
Jamie GarrochPowerPoint Consultant & DeveloperAsked:
Who is Participating?
Jamie GarrochPowerPoint Consultant & DeveloperAuthor Commented:
Thanks for the suggestion Rgonzo1971. That won't work because as I mentioned in the question, the object model is read only for the GroupItems in a 2007 SmartArt object. That's why my last resort is to use SendKeys.

JSRWilson - I'm going to continue working on it tomorrow but I think the fact that using SendKeys to send {TAB} is changing the selection so re-triggering the WindowSelectionChange event which in turn could be causing the issue. I'm not sure how single-thread VBA handles that if code is already running as a result of an event and another event occurs before the code has finished executing.
Does it work if you force the Smart Art Design Tab to open first (Alt JS)

It's always going to be ropey though.

pls try this workaround

Sub Macro1()

'Loop through each shape in the group and turn the outline off
    For Each Item In ActiveWindow.Selection.ShapeRange(1).GroupItems
        ' Item.Line.Visible = msoFalse ' not working
        Item.Line.Weight = 0
        Item.Line.Transparency = 1

End Sub

Open in new window

Martin LissOlder than dirtCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.