vba:powerpoint宏:“文件”;变量未设置";

vba:powerpoint宏:“文件”;变量未设置";,vba,powerpoint,powerpoint-2010,Vba,Powerpoint,Powerpoint 2010,我的代码中出现“对象变量或未设置块变量”错误。 这是我第一次尝试宏编写。我有编程知识,但这对我来说是新的 无论如何,我想浏览一下演示文稿,对于笔记部分中有任何文本的每一页,我想添加一张包含该文本的新幻灯片(在它后面) 以下是我尝试过的: Sub SlideSort() Dim curSlide As Slide Dim newSld As Slide Dim curPres As Presentation Dim curShape As Shape Dim i As Integer F

我的代码中出现
“对象变量或未设置块变量”
错误。 这是我第一次尝试宏编写。我有编程知识,但这对我来说是新的

无论如何,我想浏览一下演示文稿,对于笔记部分中有任何文本的每一页,我想添加一张包含该文本的新幻灯片(在它后面)

以下是我尝试过的:

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
Sub-SlideSort()
像幻灯片一样模糊的光标
暗新闻幻灯片
作为演示文稿的暗淡curPres
形状暗淡
作为整数的Dim i
对于i=1到ActivePresentation.Slides.Count
curSlide=ActivePresentation.Slides(i)
对于curSlide.NotesPage.Shapes中的每个curShape
如果curShape.Type=msoPlaceholder,则
如果curShape.PlaceholderFormat.Type=ppPlaceholderBody,则
如果curShape.TextFrame.TextRange“”则
Set newSld=ActivePresentation.Slides.Add(索引:=i+1,布局:=ppLayoutText)
newSld.Shapes(2).TextFrame.TextRange=curShape.TextFrame.TextRange
i=i+1
如果结束
如果结束
如果结束
下一个诅咒
接下来我
端接头

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

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

Set curSlide = ActivePresentation.Slides(i)

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

Set curSlide = ActivePresentation.Slides(i)

使用
Set curSlide=ActivePresentation.Slides(i)
-它是一个对象,应该通过
Set
使用
Set curSlide=ActivePresentation.Slides(i)
-它是一个对象,应该通过
Set
操作。这是Mac版PowerPoint中的一个bug。我可以在Mac电脑上重新设置这个问题

Mac PowerPoint不支持.Placeholder Format.Type,但应该支持

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

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
Sub-SlideSort()
像幻灯片一样模糊的光标
暗新闻幻灯片
作为演示文稿的暗淡curPres
形状暗淡
作为整数的Dim i
对于i=1到ActivePresentation.Slides.Count
curSlide=ActivePresentation.Slides(i)
curShape=curSlide.NotesPage.Shapes(2)
如果curShape.TextFrame.TextRange“”则
Set newSld=ActivePresentation.Slides.Add(索引:=i+1,布局:=ppLayoutText)
newSld.Shapes(2).TextFrame.TextRange=curShape.TextFrame.TextRange
i=i+1
如果结束
接下来我
端接头

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

答对了。这是Mac版PowerPoint中的一个bug。我可以在Mac电脑上重新设置这个问题

Mac PowerPoint不支持.Placeholder Format.Type,但应该支持

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

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
Sub-SlideSort()
像幻灯片一样模糊的光标
暗新闻幻灯片
作为演示文稿的暗淡curPres
形状暗淡
作为整数的Dim i
对于i=1到ActivePresentation.Slides.Count
curSlide=ActivePresentation.Slides(i)
curShape=curSlide.NotesPage.Shapes(2)
如果curShape.TextFrame.TextRange“”则
Set newSld=ActivePresentation.Slides.Add(索引:=i+1,布局:=ppLayoutText)
newSld.Shapes(2).TextFrame.TextRange=curShape.TextFrame.TextRange
i=i+1
如果结束
接下来我
端接头

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

你吃多了我31秒你吃多了我31秒谢谢!出于好奇,有没有更明智的方法来做我想做的事情?我想对于这样的宏,计算效率并不是特别重要。也许可以使用
s组合嵌套
If
s。另外,在更正set命令后,我得到了一个新错误:占位符格式(未知成员):此行失败:如果curShape.PlaceholderFormat.Type=ppPlaceholderBody,则需要在占位符集合中寻址特定项。看到这个:(不确定协议是什么…我是编辑我的原始帖子来显示新的错误…还是开始一个新的线程?)谢谢!出于好奇,有没有更明智的方法来做我想做的事情?我想对于这样的宏,计算效率并不是特别重要。也许可以使用
s组合嵌套
If
s。另外,在更正set命令后,我得到了一个新错误:占位符格式(未知成员):此行失败:如果curShape.PlaceholderFormat.Type=ppPlaceholderBody,则需要在占位符集合中寻址特定项。看到这个:(不确定协议是什么…我是编辑我的原始帖子来显示新的错误…还是启动一个新的线程?)