用于访问活动幻灯片的ActiveWindow VBA命令在虚拟机

时间:2015-05-05 10:12:05

标签: vba virtual-machine powerpoint-vba vmware-fusion

我几天前刚开始使用VBA。我注意到一些命令在我的计算机上似乎不起作用,我想知道这是否是由于我的计算机设置。

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

Set oSl = Application.ActiveWindow.View.Slide

(如建议here

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

(如建议here

Set oSl = ActiveWindow.Selection.SlideRange.SlideIndex

(如建议here

这些都不适合我。由于我刚开始使用VBA,我只是在代码的不同部分之后插入消息框,并查看何时不再触发的框 - 在这种情况下始终在“oSl =”行之后,我用上面描述的各种其他方法替换。另外,

Set oSl = ActiveWindow.Selection.SlideRange(1)

也破坏了我的代码(如here所述)

到目前为止,DID的工作是什么

Set oSl = ActivePresentation.SlideS(1)

上述所有不起作用的方法(但应该)都包含“ActiveWindow”。如果您可以建议我选择活动幻灯片的方法是否有错误,或者问题是VBA无法正确访问“ActiveWindow”,因为我的PowerPoint在虚拟机上运行,​​那将会很棒。如果是这种情况,是否有另一种方法可以在不使用ActiveWindow的情况下选择当前活动的幻灯片?

编辑:我正在尝试将此应用于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

0 个答案:

没有答案