2016-05-29 52 views
0

我想構建一個工具,用戶可以單擊Excel中的按鈕並獲取PowerPoint中選定形狀的高度,寬度,頂部,左側屬性使他們能夠更有效地在Excel中調整形狀)。從Excel中獲取PowerPoint中的形狀的維度與VBA

目前,我似乎不能夠引用在PowerPoint中選擇形狀儘管有下面的代碼:

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 

我有一種感覺,我不與PowerPoint正確交互,但不能看到是怎麼回事有可能。

+0

嘗試'debug.Print類型名稱(ActiveShape)'來驗證你的假設,你已經得到的形狀。代碼中定義的ActiveShape在哪裏? –

+0

我不知道如何在PowerPoint中做到這一點,但在Excel中它就是這樣的:'Dim Pic as Shape:Set Pic = Selection.Shaperange(1)' –

回答

0

相反的:

Set ActiveShape = PowerPointApp.ActivePresentation.ActiveWindow.Selection 

用途:

Set ActiveShape = PowerPointApp.ActiveWindow.Selection.ShapeRange(1) 
+0

是的,這工作 –