开发者

Why does this slides-creating loop in VBA PowerPoint not work?

I have tried to create this script that would create 10 empty slides, but it doesn't work for some reason:

Sub CreatingSlides()
    Dim oPresentation As Presentation
    Set oPresentation = ActivePresentation
    Dim oSlid开发者_如何学Goe 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

What have I done wrong here? Maybe my loop here is missing something?


First:

  Set myindex = 1 

should be:

  myindex = 1

Set is for object references. Let is for values and is usually implied but you could also use:

  Let myindex = 1

which has the same affect.

Second, loose the line

  myindex = myindex + 1

That's what the For/Next is doing for you. You might have some different behaviour expectations still so try this and we can go from there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜