1

ppt 的 VBA 新功能。(用来做更多的Excel vba)。当我在 PowerPoint 的 VBA 编辑器中运行它时,下面的宏非常简单并且在正常模式下运行良好。(将在屏幕中央添加一个蓝色矩形)

为了在幻灯片放映中工作,我通过动作设置选项将宏分配给随机形状,但实际上什么也没发生。谢谢

Sub Rdmrectangle()

Dim sld As Slide
Dim shp As Shape
Dim SlideIndex As Long

SlideIndex = ActiveWindow.View.Slide.SlideIndex

Set sld = ActivePresentation.Slides(SlideIndex)

Set shp = sld.Shapes.AddShape(Type:=msoShapeRectangle, _
    Left:=50, Top:=50, Width:=100, Height:=200)

With ActivePresentation.PageSetup
shp.Left = (.SlideWidth \ 2) - (shp.Width \ 2)
shp.Top = (.SlideHeight \ 2) - (shp.Height \ 2)
End With

shp.Fill.ForeColor.RGB = vbBlue

shp.ZOrder msoBringToFront
End Sub
4

1 回答 1

0

如果您需要它在幻灯片放映模式下工作,您可以使用ActivePresentation.SlideShowWindow.View.

Sub Rdmrectangle()

    Dim sld As slide
    Set sld = ActivePresentation.SlideShowWindow.View.Slide

    Dim shp As Shape
    Set shp = sld.Shapes.AddShape(Type:=msoShapeRectangle, _
        Left:=50, Top:=50, Width:=100, Height:=200)

    With ActivePresentation.PageSetup
        shp.Left = (.SlideWidth \ 2) - (shp.Width \ 2)
        shp.Top = (.SlideHeight \ 2) - (shp.Height \ 2)
    End With

    shp.Fill.ForeColor.RGB = vbBlue
    shp.ZOrder msoBringToFront
End Sub
于 2019-10-11T00:28:02.080 回答