0

I'm trying to build a tool whereby users can click a button in Excel and get the height, width, top, left properties of a selected shape in PowerPoint (to enable them to size shapes in Excel more effectively).

Currently I don't seem to be able to reference the selected shape in PowerPoint despite having the following code:

Dim PowerPointApp As Object
Dim ActivePresentation As Object
Dim ActiveSlide As Object

Public Sub getDimensionsFromPowerPoint()

    'Create an Instance of PowerPoint
    On Error Resume Next

    'Is PowerPoint already opened?
    Set PowerPointApp = GetObject(Class:="PowerPoint.Application")

    'Clear the error between errors
    err.Clear

    'If PowerPoint is not already open then open PowerPoint
    If PowerPointApp Is Nothing Then Set PowerPointApp = CreateObject(Class:="PowerPoint.Application")

    'Handle if the PowerPoint Application is not found
    If err.Number = 429 Then
        MsgBox "PowerPoint could not be found, aborting."
        Exit Sub
    End If

    On Error GoTo 0

    'Optimize Code
    Application.ScreenUpdating = False

    'Create a New Presentation

    Set ActiveShape = PowerPointApp.ActivePresentation.ActiveWindow.Selection

    Debug.Print ActiveShape.width

End Sub

I have a feeling I'm not interacting with PowerPoint properly but cannot see how else it can be.

2
  • Try debug.Print typename(ActiveShape) to verify your assumption that you have got a shape. Where is ActiveShape defined in your code? Commented May 29, 2016 at 22:17
  • i don't know how to do it in powerpoint, but in excel it is like that : Dim Pic as Shape : Set Pic = Selection.Shaperange(1) Commented May 30, 2016 at 8:29

2 Answers 2

0

Instead of:

 Set ActiveShape = PowerPointApp.ActivePresentation.ActiveWindow.Selection

Use:

 Set ActiveShape = PowerPointApp.ActiveWindow.Selection.ShapeRange(1)
Sign up to request clarification or add additional context in comments.

Comments

0

From this web page https://msdn.microsoft.com/en-us/library/office/ff745871.aspx

It looks like you need to use the ShapeRange method to get references to shapes.

I think ShapeRange supports For Each because (1) so you can loop through them.

(1) Evidence for support For Each is presence of hidden _NewEnum method.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.