MinhKhai
Giải pháp Ếc-xào
- Tham gia
- 16/4/08
- Bài viết
- 941
- Được thích
- 574
Em áp dụng cách ngăn cản việc in 1 bảng tính thông qua lệnh Print bằng code sưu tập trong diễn đàn cụ thể là:
Mục tiêu chính của em là muốn người dùng in thông qua 1 nút lệnh CommandButton tự tạo (Nút lệnh này kiểm tra 1 vài thứ trước khi PrintOut).
Tuy nhiên em không biết cài mã VBA như thế nào để CommandButton tạm thời hủy lệnh không cho in như code trên.
Xin mọi người chỉ dẫn.
Mã:
[COLOR=#007700][FONT=monospace]Private [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Sub workbook_BeforePrint[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Cancel [/FONT][/COLOR][COLOR=#007700][FONT=monospace]As [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Boolean[/FONT][/COLOR][COLOR=#007700][FONT=monospace])
[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Select [/FONT][/COLOR][COLOR=#007700][FONT=monospace]Case [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]ActiveSheet[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Name
[/FONT][/COLOR][COLOR=#007700][FONT=monospace]Case [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"Sheet1"[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"Sheet2"
[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Cancel [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]True
MsgBox [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"Xin loi, Ban khong the in bang cach nay"[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]vbInformation
End Select
End Sub
[/FONT][/COLOR]
Tuy nhiên em không biết cài mã VBA như thế nào để CommandButton tạm thời hủy lệnh không cho in như code trên.
Xin mọi người chỉ dẫn.