Sub 手動雙面打印() Dim Pages As Long Dim myBottonNum As Integer Dim myPrompt1 As String Dim myPrompt2 As String myPrompt1 = "在打印時發(fā)生錯誤,請檢查你的打印機設置" myPrompt2 = "請將出紙器中已打印好一面的紙取出并將其放回到送紙器中,然后按下""確定"",繼續(xù)打印" Pages = ExecuteExcel4Macro("Get.Document(50)") '統(tǒng)計總頁數 On Error Resume Next If (Pages = 0) Then '如果為零,說明沒有可打印內容,退出程序 MsgBox "Microsoft Excel 未發(fā)現(xiàn)任何可以打印的內容", 0 + 48 Exit Sub End If If (Pages = 1) Then '判斷是否只有一頁,如果是,只打印第一頁,然后退出 ActiveSheet.PrintOut If Err.Number = 1004 Then MsgBox myPrompt1, 0 + 48 '提示用戶發(fā)生打印錯誤 End If Exit Sub End If For i = 1 To Pages Step 2 '設置循環(huán),打印奇數頁 ActiveSheet.PrintOut From:=i, To:=i 'ActiveSheet.PrintOut Copies:=3 From:=i, To:=i 打印3份 If Err.Number = 1004 Then MsgBox myPrompt1, 0 + 48 Exit Sub End If Next i myBottonNum = MsgBox(myPrompt2, 1 + 48) '提示用戶取出紙張,確認后繼續(xù)打印 If (myBottonNum = 1) Then For j = 2 To Pages Step 2 '打印偶數頁 ActiveSheet.PrintOut From:=j, To:=j Next j End If End Sub |
按Alt+Q返回到工作表窗口,單擊菜單“工具”→“自定義”,在彈出的自定義對話框中選擇“命令”選項卡,在命令選項卡中選擇“宏”→“自定義按鈕”。
到此,命令基本添加完畢!