简体   繁体   English

为什么 VBA PowerPoint 中的此幻灯片创建循环不起作用?

[英]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:我试图创建这个脚本来创建 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

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. Set 用于对象引用。 Let is for values and is usually implied but you could also use: Let 用于值,通常是隐含的,但您也可以使用:

  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.这就是 For/Next 正在为您做的事情。 You might have some different behaviour expectations still so try this and we can go from there.您可能仍然有一些不同的行为期望,所以试试这个,我们可以从那里开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM