【问题标题】:PrintOut method prints random pagesPrintOut 方法打印随机页面
【发布时间】:2012-07-11 18:01:15
【问题描述】:

我在 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 个值,而不是打印工作表(这实际上没有意义)。在所有工作表上设置和检查打印范围,我真的不明白错误来自哪里。

有什么想法吗?

先谢谢了!

【问题讨论】:

  • 当我首先点击按钮时,会打开一个弹出窗口,其中包括我要打印的 X 页(并且它会正确打印它们),然后“Print Y of X..”弹出窗口关闭,另一个弹出窗口打开声明“Print 1 of 196”和随机页面。我不知道第二个打印命令来自该代码的哪里......
  • 您调用 PrintOut 两次 - 为什么?
  • "Print 1 of 196" 打印范围有问题。您可能想再次检查它。对每张纸都使用它,看看你得到了什么地址? Debug.Print UsedRange.Address
  • 您是否尝试过使用PrintPreview 来查看是否可以拼凑出随机值的来源?节省纸张!

标签: vba printing excel excel-2007


【解决方案1】:

您仍然可以通过这种方式使用 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

【讨论】:

    猜你喜欢
    • 2023-03-12
    • 2011-07-17
    • 1970-01-01
    • 2010-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-15
    相关资源
    最近更新 更多