为什么这个幻灯片创建循环在VBA PowerPoint中不起作用?

bri*_*ant 2 powerpoint powerpoint-vba

我试图创建这个脚本,创建10个空幻灯片,但由于某些原因它不起作用:

Sub CreatingSlides()
    Dim oPresentation As Presentation
    Set oPresentation = ActivePresentation
    Dim oSlide As Slide
    Dim oSlides As SlideRange
    Dim oShape As Shape
    Dim slideNumber As Integer
    Dim myindex As Integer

    Set myindex = 1
    ActivePresentation.Slides.add(Index:=myindex, Layout:=ppLayoutBlank).Select
    For myindex = 1 To 10
        myindex = myindex + 1
        ActivePresentation.Slides.add(Index:=myindex, Layout:=ppLayoutBlank).Select
    Next myindex
End Sub
Run Code Online (Sandbox Code Playgroud)

我在这做错了什么?也许我的循环在这里缺少一些东西?

Swa*_*nny 5

第一:

  Set myindex = 1 
Run Code Online (Sandbox Code Playgroud)

应该:

  myindex = 1
Run Code Online (Sandbox Code Playgroud)

Set用于对象引用.让我们为价值而且通常暗示,但您也可以使用:

  Let myindex = 1
Run Code Online (Sandbox Code Playgroud)

具有相同的影响.

第二,松散线

  myindex = myindex + 1
Run Code Online (Sandbox Code Playgroud)

这就是For/Next为你做的事情.你可能会有一些不同的行为期望,所以试试这个,我们可以从那里开始.