Link to home
Start Free TrialLog in
Avatar of Jamie Garroch (MVP)
Jamie Garroch (MVP)Flag for United Kingdom of Great Britain and Northern Ireland

asked on

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
  Next

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?
Avatar of John Wilson
John Wilson
Flag of United Kingdom of Great Britain and Northern Ireland image

Does it work if you force the Smart Art Design Tab to open first (Alt JS)

It's always going to be ropey though.
Avatar of Rgonzo1971
Rgonzo1971

Hi,

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
    Next

'
End Sub

Open in new window

Regards
ASKER CERTIFIED SOLUTION
Avatar of Jamie Garroch (MVP)
Jamie Garroch (MVP)
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.