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 GarrochSenior Technical Consultant at BrightCarbonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Jamie GarrochSenior Technical Consultant at BrightCarbonAuthor 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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.