我几天前才刚开始使用VBA。我注意到一些命令似乎在我的计算机上不起作用,我想知道这是否是由于我的计算机设置引起的。
我正在通过MacOSX上的VMware Fusion(虚拟机)运行的Windows 7上的PowerPoint 2013中使用VBA。我需要创建对活动幻灯片的动态引用,但是这样做的几种方法破坏了我的代码:
Set oSl = Application.ActiveWindow.View.Slide
(如建议在这里)
Set oSl = ActivePresentation.Slides(ActiveWindow.View.Slide.SlideNumber)
(如建议在这里)
Set oSl = ActiveWindow.Selection.SlideRange.SlideIndex
(如建议在这里)
这些都不对我有用。因为我刚开始使用VBA,所以我只是在代码的不同部分之后插入了消息框,并查看何时不再触发该框-在这种情况下,总是在“ oSl =”行之后,我用上面描述的各种其他方法替换了。此外,
Set oSl = ActiveWindow.Selection.SlideRange(1)
也打破了我的代码(如讨论这里)
到目前为止,DID的工作是
Set oSl = ActivePresentation.SlideS(1)
上面所有不起作用(但应该)的方法都包含“ ActiveWindow”。如果您可以建议我选择活动幻灯片的方式是否存在错误,或者问题可能是由于我的PowerPoint在虚拟机上运行而导致VBA无法正确访问“ ActiveWindow”,那么这将是很好的选择。如果是这样,是否还有另一种方法可以选择不使用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
我有类似的问题。
尝试更换:
ActiveWindow.View.Slide.SlideNumber
和:
ActivePresentation.SlideShowWindow.View.Slide.SlideIndex
这是我在项目中需要的,也许可以为您提供帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句