SectionProperties.AddSection工作不正常 - 错误?

问题描述:

我刚刚遇到了SectionProperties.AddSection的错误行为。比方说,我已经创建了四个部分:SectionProperties.AddSection工作不正常 - 错误?

1. Default 
2. Overview 
3. Details 
4. Conclusions 

现在我叫代码:

Presentation.SectionProperties.AddSection(3, "Overview details"); 

根据文档:SectionProperties.AddSection Method (PowerPoint)概要细节部分前应详细信息部分创建。

而不是让

1. Default 
2. Overview 
3. Overview Details 
4. Details 
5. Conclusions 

我结束了但是:

1. Default 
2. Overview details 
3. Overview 
4. Details 
5. Conclusions 

它是一个常见的问题?我做了一些测试,似乎只有在开始或结束插入新节时插入新节才能正常工作。

感谢, 帕维尔

+0

我甚至发现行为异常。在一篇演讲中,在sectino 3中有一张幻灯片,在前两节中没有幻灯片,添加一个新节会导致在演示开始时添加节,即索引1,无论我指定的索引如何,除非它是4 (即比现有部分的数量多一个,在这种情况下,它是在演示结束时添加的)。如果您希望它能够工作,您似乎至少需要在现有部分之前和之后插入新部分的幻灯片。越野车的确如此。 – 2012-02-11 17:35:45

看到你在MS答案后,以及在之间,有一点更多的时间玩这个。这确实是越野车,但有一个解决方法。当某些部分没有幻灯片时会出现问题;所以我们将幻灯片添加到任何没有它们的部分,根据需要添加部分,然后删除刚刚添加的“虚拟”幻灯片。

Sub TestAddSection() 
    Dim x As Long 
    Dim oSl As Slide 

    ' Add a dummy slide to each empty section and tag it 
    For x = 1 To ActivePresentation.SectionProperties.Count 
     Debug.Print ActivePresentation.SectionProperties.Name(x) 
     If ActivePresentation.SectionProperties.SlidesCount(x) = 0 Then 
      ' activepresentation.SectionProperties. 
      Set oSl = ActivePresentation.Slides.AddSlide(1, ActivePresentation.Designs(1).SlideMaster.CustomLayouts(1)) 
      oSl.Tags.Add "DUMMY", "YES" 
      oSl.MoveToSectionStart (x) 
     End If 
    Next 

    ' add new section 
    ActivePresentation.SectionProperties.AddSection 3, "NEW GUY" 

    ' And delete the dummy slides 
    With ActivePresentation 
     For x = .Slides.Count To 1 Step -1 
      If .Slides(x).Tags("DUMMY") = "YES" Then 
       .Slides(x).Delete 
      End If 
     Next 
    End With 
End Sub 

我在索引1中添加幻灯片,然后将它们移动到需要它们的部分的开始位置。也许有办法直接将它们添加到该部分,但我找不到它。