gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 23:43:57 24 4
gpt4 key购买 nike

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

我在通过 MacOSX 上的 VMware Fusion(虚拟机)运行的 Windows 7 上的 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 )

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

Set oSl = ActiveWindow.Selection.SlideRange(1)

也破坏了我的代码(如讨论 here )

到目前为止 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 

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

关于vba - 用于访问事件幻灯片的 ActiveWindow VBA 命令在虚拟机上运行的 PowerPoint 2013 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30050130/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com