PrintOut方法打印随机页面

时间:2012-07-11 18:01:15

标签: excel vba printing excel-vba excel-2007

我在Excel中有一个打印输出按钮,分配给以下代码:

Private Sub CommandButton1_Click()
    Application.ScreenUpdating = False
    Sheets(Array("Cover", "1", "1-1", "2", "3", "4")).PrintOut , , 1
    Sheet1.PrintOut , , 1 'use this method to print all together at the end instead printing individually.
    Application.ScreenUpdating = True
End Sub

然而,不是打印纸张,而是开始打印100个随机页面,每页3-10个值(这没有用)。在所有工作表中设置和检查打印范围,我真的不明白错误的来源。

有什么想法吗?

先谢谢!

1 个答案:

答案 0 :(得分:0)

您仍然可以这样使用PrintOut:

Private Sub CommandButton1_Click()
    Application.ScreenUpdating = False

    'If you want only to print the active sheet
    Sheet1.PrintOut

    'Printing a range, from the first page until page 23, one copy:
    Sheet1.PrintOut 1,23,1

    'Printing only a single page (23), two copies:
    Sheet1.PrintOut 23,23,2

    Application.ScreenUpdating = True
End Sub

看一下: https://msdn.microsoft.com/en-us/library/office/ff838253.aspx