【发布时间】:2016-09-27 16:17:45
【问题描述】:
我正在尝试构建一个工具,用户可以在该工具中单击 Excel 中的按钮并在 PowerPoint 中获取所选形状的高度、宽度、顶部、左侧属性(使他们能够更有效地在 Excel 中调整形状的大小)。
尽管有以下代码,但目前我似乎无法在 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 的交互不正常,但看不到其他情况。
【问题讨论】:
-
尝试
debug.Print typename(ActiveShape)来验证您的假设,即您有一个形状。 ActiveShape 在您的代码中定义在哪里? -
我不知道如何在 powerpoint 中做到这一点,但在 excel 中是这样的:
Dim Pic as Shape : Set Pic = Selection.Shaperange(1)
标签: vba excel ms-office powerpoint