使用VBA遍历范围以在PowerPoint中打印特定幻灯片

时间:2018-11-06 20:37:11

标签: vba powerpoint

我尝试使用此命令或类似的宏进行打印,并且可以正常工作,然后导出,然后excel崩溃了。然后,我在重新启动后无法使它正常工作。

宏应循环用户输入的次数,然后以6次幻灯片讲义上循环的次数的倍数打印第一张幻灯片(标题)和5个其他幻灯片索引。

  • 第一页:1、3-7
  • 第二页:1、8-12
  • 第三页:1、13-17

这现在会引发错误:

  

运行时错误'-2147467259(80004005)

     

对象'_Presentation'的方法'PrintOut'失败

下面是我的脚本。想法?

Sub CHPrint()

    Dim oIndexArray(0 To 5) As Integer, slideIndexArray(0 To 5) As Integer, numCases As Integer

    ' Prompt user for how many cases to print (# pages, # loops)
    numCases = InputBox("How many cases to print?")

    ' Initialize first index of array to 1 (first slide).  This will not change.
    slideIndexArray(0) = 1

    ' Initialize other indices of array to the first set of slides to print (3-7)
    For i = 1 To 5
        oIndexArray(i) = 3 + (i - 1)
        slideIndexArray(i) = oIndexArray(i)
        Next i

    ' For each loop, select slides to print (1&3-7; 1&8-12; 1&13-17; etc.) and print
    For i = 0 To numCases - 1

        ActivePresentation.Slides.Range(slideIndexArray).Select

        With ActivePresentation
            With .PrintOptions
                .ActivePrinter = "LN104142 on LocalHost"
                '.ActivePrinter = "Adobe PDF"
                .OutputType = ppPrintOutputSixSlideHandouts
                .RangeType = ppPrintSelection
                End With
            .PrintOut  ' "method 'printout' of object '_presentation' failed"

            End With

            ' For each time through the first loop (i), reinitialize selection (1&3-7; 1&8-12; 1&13-17; etc.)
            For j = 1 To 5
                slideIndexArray(j) = oIndexArray(j) + (5 * (i + 1))
            Next j

        Next i

End Sub

0 个答案:

没有答案