1

我的 "Object variable or With block variable not set"代码出现错误。这是我第一次写宏。我确实有编程知识,但这对我来说是新的。

无论如何,我想通过演示文稿,并且对于在注释部分中有任何文本的每一页,我想添加一张包含该文本的新幻灯片(在它之后)。

这是我尝试过的:

Sub SlideSort()
Dim curSlide As Slide
Dim newSld As Slide
Dim curPres As Presentation
Dim curShape As Shape
Dim i As Integer

    For i = 1 To ActivePresentation.Slides.Count
        curSlide = ActivePresentation.Slides(i)

        For Each curShape In curSlide.NotesPage.Shapes
            If curShape.Type = msoPlaceholder Then
                If curShape.PlaceholderFormat.Type = ppPlaceholderBody Then
                    If curShape.TextFrame.TextRange <> "" Then
                        Set newSld = ActivePresentation.Slides.Add(Index:=i + 1, Layout:=ppLayoutText)
                        newSld.Shapes(2).TextFrame.TextRange = curShape.TextFrame.TextRange
                        i = i + 1

                    End If
                End If
            End If
        Next curShape
    Next i

End Sub

给出错误的行是 curSlide = ActivePresentation.Slides(i)

4

3 回答 3

3

使用Set curSlide = ActivePresentation.Slides(i)- 它是一个对象,应该通过Set.

于 2013-02-26T18:35:44.177 回答
1

您需要在此处使用 Set ,就像使用其他对象一样:

Set curSlide = ActivePresentation.Slides(i)
于 2013-02-26T18:35:14.623 回答
0

答对了。这是 PowerPoint 的 Mac 版本中的一个错误。我可以在 Mac 上重现该问题。

Mac PowerPoint 不支持 .PlaceholderFormat.Type,但应该支持。

它不是 100% 可靠的,但您可以在笔记页面上选择第二个形状作为正文占位符:

Sub SlideSort()
Dim curSlide As Slide
Dim newSld As Slide
Dim curPres As Presentation
Dim curShape As Shape
Dim i As Integer

    For i = 1 To ActivePresentation.Slides.Count
        curSlide = ActivePresentation.Slides(i)
        curShape = curSlide.NotesPage.Shapes(2)
           If curShape.TextFrame.TextRange <> "" Then
              Set newSld = ActivePresentation.Slides.Add(Index:=i + 1, Layout:=ppLayoutText)
              newSld.Shapes(2).TextFrame.TextRange = curShape.TextFrame.TextRange
              i = i + 1
           End If
    Next i

End Sub

我怀疑您也可能遇到问题,因为您正在循环中查看 Slide.Count,但是通过添加幻灯片,您正在修改 Slide.Count。

于 2013-02-27T15:47:44.630 回答