我想构建一个工具,用户可以单击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正确交互,但不能看到是怎么回事有可能。
尝试'debug.Print类型名称(ActiveShape)'来验证你的假设,你已经得到的形状。代码中定义的ActiveShape在哪里? –
我不知道如何在PowerPoint中做到这一点,但在Excel中它就是这样的:'Dim Pic as Shape:Set Pic = Selection.Shaperange(1)' –