SectionProperties.AddSection 无法正常工作 - bug?

发布于 2025-01-04 10:08:48 字数 719 浏览 3 评论 0原文

我刚刚遇到了SectionProperties.AddSection 的错误行为。假设我已经创建了四个部分:

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

现在我调用代码:

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

根据文档: SectionProperties.AddSection 方法 (PowerPoint) 概述详细信息 部分应在详细信息部分之前创建。

没有得到

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

但我最终

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

答案:这是一个常见问题吗?我做了一些测试,似乎只有在开头或结尾插入新部分时,插入新部分才能正常工作。

谢谢, 帕韦乌

I've just came across a buggy behaviour of SectionProperties.AddSection. Let's say I have four sections already created:

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

And now I call a code:

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

According to the documentation: SectionProperties.AddSection Method (PowerPoint) Overview Details section should be created before Details section.

But instead of getting

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

I end up with:

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

Is it a common issue? I did some testing and it seems that inserting new sections works properly only when new section is inserted at the beginning or end.

Thanks,
Paweł

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心不设防 2025-01-11 10:08:48

在 MS Answers 上也看到了您的帖子,在这之间,有更多的时间来研究这个。这确实有问题,但有一个解决方法。当某些部分没有幻灯片时会出现此问题;因此,我们将向任何没有幻灯片的部分添加幻灯片,根据需要添加该部分,然后删除刚刚添加的“虚拟”幻灯片。

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 处,然后将它们移动到需要它们的部分的开头。也许有一种方法可以将它们直接添加到该部分,但我找不到。

Saw your post on MS Answers as well and in between, had a bit more time to play with this. It's indeed buggy, but there's a workaround. The problem occurs when there are no slides in some sections; so we'll add slides to any sections that don't have them, add the section as needed, then delete the just-added "dummy" slides.

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

I'm adding the slides at index 1 then moving them to the start of the section where they're needed. Perhaps there's a way to add them directly to the section, but I couldn't find it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文