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.
debug.Print typename(ActiveShape)to verify your assumption that you have got a shape. Where is ActiveShape defined in your code?Dim Pic as Shape : Set Pic = Selection.Shaperange(1)