Positioning the selected object (a table) in Powerpoint 2010

I have a macro in Excel that copies a range and then pastes it into PPT as a table. At which point I want to position it.  As it stands now Line 1 moves other shapes around but leaves the desired one alone.
With .Slides(2).Shapes(.Slides(2).Shapes.Count)
 .Top = 74
 .Left = 20
End With

Open in new window

What I want to do is take the actively selected table on Slide 2 (the one that was just pasted in) and position it as shown.  One way to do it would the PPT equivalent of this code in Excel:
With Selection
 .Left = 40
 .top = 70
End With

Open in new window


Another way would be to rename the table and then reference it as the object to be positioned. You know, the equivalent of
With ActiveSheet.Shapes("DarkFlightTable")
 .Left = 40
 .top = 70
End With

Open in new window


How do I write it so that PPT understands it? Please let me know how to write it both ways if possible

Thanks!
John
LVL 1
John CarneyReliability Business Tools Analyst IIAsked:
Who is Participating?

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

x
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.

Rgonzo1971Commented:
Hi,

pls try (if the name of the shape is right in PPT)

With ActivePresentation.Slides(2).Shapes("DarkFlightTable")
 .Left = 40
 .top = 70
End With

Open in new window

Regards
Jamie GarrochSenior Technical Consultant at BrightCarbonCommented:
If the table (or any object aka shape) is selected, you can use this::

With ActiveWindow.Selection.ShapeRange(1)
  .Left = 40
  .Top = 70
End With

Open in new window

John CarneyReliability Business Tools Analyst IIAuthor Commented:
I just discovered that if I set a breakpoint on "With ActiveWindow.Selection.ShapeRange(1)" and step through the code it works. Here's the full code. Do you see anything that could be causing that and what would be the fix?
Sub RangeToPresentation()
Dim PPApp  As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Dim objName As String
Set rng = Range([B1], [G13].End(xlUp))
    rng.Copy
    Set PPApp = GetObject(, "Powerpoint.Application")
    Set PPPres = PPApp.ActivePresentation
    PPApp.ActiveWindow.ViewType = ppViewSlide
    With PPPres
        .Windows(1).Activate
        .Windows(1).View.GotoSlide 2
        .Application.CommandBars.ExecuteMso ("PasteSourceFormatting")
    End With
With PPApp.ActiveWindow.Selection.ShapeRange(1)
 .Left = 25
 .top = 74
 .Height = 192
End With
End Sub

Open in new window

Thanks,
John
Jamie GarrochSenior Technical Consultant at BrightCarbonCommented:
That would point to a timing issue AFAIK :-(

This type of situation can often arise when pasting objects whereby the code continues running before the object is fully registered as being part of the presentation. One way round it could be to either add a delay before your error generating line (but this won't address different PC configs), add a DoEvents line after the paste, or to put a loop in to detect when the object is selected. Something like (untested) this:

Do While PPApp.ActiveWindow.Selection.Type = ppSelectionNone
  DoEvents
Loop

Open in new window


And then make sure you unselect the object at the end with:

PPApp.ActiveWindow.Selection.Unselect

Open in new window

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
John CarneyReliability Business Tools Analyst IIAuthor Commented:
Jamie, thanks! you're making me look to my co-workers like I know what I'm doing  :- )

John
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
Microsoft PowerPoint

From novice to tech pro — start learning today.