使用“打印为PDF"宏按钮时,如何禁用Excel Excel以外的工作簿打印? [英] How can I disable printing an excel workbook EXCEPT when using a Print-to-PDF macro button?

查看:84
本文介绍了使用“打印为PDF"宏按钮时,如何禁用Excel Excel以外的工作簿打印?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了该站点,但找不到答案.

I searched the site and could not find an answer for this.

背景:我将此宏作为工作表上的按钮.它可以很好地满足我的需求:

Background: I have this Macro as a button on a worksheet. It works well for what I need:

Sub FactSheetSaveToPDF()

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\" & Range("b2") & " - " & Month(Date) & "." & Day(Date) & "." &     Year(Date) & "." _
      & Hour(Time) & Minute(Time) & Second(Time) & ".pdf",     Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End Sub

我现在需要做的就是使其符合标准,以便用户只能使用这些按钮进行打印.因此,无论是禁用,阻止还是禁止常规打印,此excel文档的用户只有按一下按钮以打印为PDF时,才能够打印工作表.某人无法在此宏按钮之外进行打印.CTRL + P,文件打印,全部禁止.

What I need to do now is make it so that a user can ONLY print using these buttons, for compliance reasons. So, whether normal printing is disabled, blocked, whatever, a user of this excel document should only be able to print a worksheet if they hit the button to print to PDF. There cannot be an ability for someone to print outside of this macro button. CTRL+P, file-print, all not allowed.

我看到一个答案,它禁止了所有打印,包括从宏中进行的打印.这是行不通的.打印为PDF"宏按钮需要工作.

I saw one answer that disabled all printing, including from the macro. This will not work. The Print-to-PDF macro button needs to work.

我看到了另一个答案,该答案禁止了用户可能已经打开的所有功能.这对于一个人来说太强大了.我只想禁用此特定excel文档的打印.

I saw another answer that disabled all printing from all excels that the user may have open; this is too much power for one man. I only want to disable printing from this particular excel document.

我假设我将不得不创建一些代码来禁用所有打印,然后修改宏以使打印"按钮成为一个例外,或者是它的某些变体.

I assume I will have to create some code that disables all printing, and then amend the macro for the print button to be an exception, or some variation of that.

如果你没有注意到我的白话,我是 VBA 的初学者.试图使其尽可能简单.非常感谢您的帮助.

If you haven't noticed by my vernacular, I am a beginner, if that, at VBA. Trying to keep it as simple as possible. I greatly appreciate any help.

推荐答案

简单.在工作簿代码区域中使用它:

Easy. Use this in the workbook code area:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Cancel = True
End Sub

这将停止用户,但在您的按钮代码中:

This will stop the User, but in your button code:

Sub FactSheetSaveToPDF()
    Application.EnableEvents = False
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
            "C:\" & Range("b2") & " - " & Month(Date) & "." & Day(Date) & "." & Year(Date) & "." _
              & Hour(Time) & Minute(Time) & Second(Time) & ".pdf", Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, IgnorePrintAreas:=False, _
            OpenAfterPublish:=True
    Application.EnableEvents = True
End Sub

这篇关于使用“打印为PDF"宏按钮时,如何禁用Excel Excel以外的工作簿打印?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆