用于访问活动幻灯片的 ActiveWindow VBA 命令在虚拟机上的 PowerPoint 2013 运行 上不起作用

ActiveWindow VBA commands to access active slide does not work on PowerPoint 2013 running on virtual machine

我几天前才开始使用 VBA。我注意到有些命令似乎无法在我的计算机上运行,​​我想知道这是否是由于我的计算机设置所致。

我在 Windows 7 运行 上通过 MacOSX 上的 VMware Fusion(虚拟机)在 PowerPoint 2013 中使用 VBA。我需要创建对活动幻灯片的动态引用,但是这样做的几种方法破坏了我的代码:

Set oSl = Application.ActiveWindow.View.Slide

(建议here

Set oSl = ActivePresentation.Slides(ActiveWindow.View.Slide.SlideNumber)

(建议here

Set oSl = ActiveWindow.Selection.SlideRange.SlideIndex

(建议here

None 其中对我有用。因为我刚开始使用 VBA,所以我只是在代码的不同部分之后插入了消息框,然后查看消息框何时不再触发 - 在这种情况下,总是在 "oSl =" 行之后,我用上面描述的各种其他方法。此外,

Set oSl = ActiveWindow.Selection.SlideRange(1)

也破坏了我的代码(正如所讨论的

到目前为止所做的工作是

Set oSl = ActivePresentation.SlideS(1)

以上所有无效(但应该)的方法都包含"ActiveWindow"。如果您能就我 select 使用活动幻灯片的方法是否存在错误或问题是否可能是 VBA 无法正确访问 "ActiveWindow" 提出建议,那就太好了,因为我的 PowerPoint 运行s 在虚拟机上。如果是这样,是否有另一种方法可以在不使用 ActiveWindow 的情况下 select 当前活动的幻灯片?

编辑:我正在尝试将其应用于 PowerPoint 中的以下代码。基本上我想要做的是用一行代码替换 "oSl = ActivePresentation.SlideS(1)" 行,该代码行不会始终针对幻灯片 1,而是当前处于活动状态的幻灯片。我的问题不是如何做到这一点 - 有很多关于如何在线进行的说明。我的问题是为什么这些方法对我不起作用。

Sub SelectionMacro()

Dim oSl As Slide
Dim oSh As Shape
Dim aArrayOfShapes() As Variant
Dim ShapeX As Shape
Dim N As Long
Dim Temp As Variant
Dim J As Long
Dim FadeEffect As Effect

Set oSl = ActivePresentation.SlideS(1)

'This section creates an array of all pictures on Slide1 called
'"aArrayOfShapes"
For Each oSh In oSl.Shapes
    If oSh.Type = msoPicture Then
        On Error Resume Next
        Debug.Print UBound(aArrayOfShapes)
        If Err.Number = 0 Then
            ReDim Preserve aArrayOfShapes(1 To UBound(aArrayOfShapes) + 1)
        Else
            ReDim Preserve aArrayOfShapes(1 To 1)
        End If
        Set aArrayOfShapes(UBound(aArrayOfShapes)) = oSh
    End If
Next

'This section creates a random index number within the bounds of the
'length of aArrayOfShapes and assigns the shape with that index number
'to the Shape object ShapeX
Randomize
NumberX = Int((UBound(aArrayOfShapes) - (LBound(aArrayOfShapes) - 1)) * Rnd) + LBound(aArrayOfShapes)
Set ShapeX = aArrayOfShapes(NumberX)

'This section shuffles aArrayOfShapes
For N = LBound(aArrayOfShapes) To UBound(aArrayOfShapes)
    J = CLng(((UBound(aArrayOfShapes) - N) * Rnd) + N)
        If N <> J Then
            Set Temp = aArrayOfShapes(N)
            Set aArrayOfShapes(N) = aArrayOfShapes(J)
            Set aArrayOfShapes(J) = Temp
        End If
    Next N

'This section loops through all Shapes in aArrayOfShapes and
'fades them out one by one EXCEPT for ShapeX
For Each Shape In aArrayOfShapes
    If ShapeX.Name <> Shape.Name Then
    Set FadeEffect = oSl.TimeLine.MainSequence.AddEffect _
    (Shape:=Shape, effectid:=msoAnimEffectFade, trigger:=msoAnimTriggerAfterPrevious)
        With FadeEffect
        .Timing.Duration = 0.5
        .Exit = msoTrue
        End With
    End If
Next Shape

End Sub

我遇到了类似的问题。

尝试替换:

ActiveWindow.View.Slide.SlideNumber 

与:

ActivePresentation.SlideShowWindow.View.Slide.SlideIndex 

这是我项目中需要的,也许对你有帮助。