Link to home
Start Free TrialLog in
Avatar of John Carney
John CarneyFlag for United States of America

asked on

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
Avatar of Rgonzo1971
Rgonzo1971

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

Avatar of John Carney

ASKER

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

John