2012-07-11 82 views
0

我有在Excel中的打印輸出按鈕被分配給以下代碼:而不是打印紙張它開始關閉打印每3-10值100隨機頁打印方法打印的隨機頁面

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 

然而,頁面(它並沒有真正意義)。打印範圍設置和檢查跨所有工作表,我真的不明白錯誤來自哪裏。

任何想法?

非常感謝!

+0

當我按下按鈕,首先彈出的打開其中包括X頁我想打印(和它打印他們是正確的),然後「Print Y of X ..」彈出關閉另一個彈出窗口打開,顯示「Print 1 of 196」,隨機頁面被打開。我不知道從第二個打印命令來自哪個代碼的位置... – user1507035 2012-07-11 18:07:48

+1

您打給PrintOut兩次 - 爲什麼? – 2012-07-11 18:29:41

+0

'「打印1 of 196」'打印範圍不對。您可能需要再次檢查。爲每張紙使用這個,看看你有什麼地址? 'Debug.Print UsedRange.Address' – 2012-07-11 18:39:12

回答

0

您仍然可以使用打印輸出以這種方式:

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