Excel 限制要打印的份数
我有5台电脑和两台打印机通过局域网连接。其中一台计算机中有一个特定的excel文档(未共享),我希望将可打印的副本数限制为4份。这意味着用户打印该文档的副本不应超过4份 我知道影印(还有更多)的漏洞,但我仍然希望印刷品的数量能得到控制或限制 我浏览了一些打印控制软件的功能,但我了解到它们都有一个“配额”系统,用户在超过限额后必须支付打印费用。恐怕这对我不起作用 我也看到了一个类似问题的答案 谢天谢地,这个答案对我帮助很大,只是我不知道如何限制或限制用户打印超出指定数字的内容 我也读过很多答案,说限制拷贝数几乎是不可能的,但我仍然希望寻求帮助——也许能找到一些解决办法 我对计算机/打印机编程没有太深的知识。虽然不是专业人士,但我对excel vba有点熟悉 请告诉我是否有任何解决方案 我一找到东西就把它贴在这里Excel 限制要打印的份数,excel,printing,vba,Excel,Printing,Vba,我有5台电脑和两台打印机通过局域网连接。其中一台计算机中有一个特定的excel文档(未共享),我希望将可打印的副本数限制为4份。这意味着用户打印该文档的副本不应超过4份 我知道影印(还有更多)的漏洞,但我仍然希望印刷品的数量能得到控制或限制 我浏览了一些打印控制软件的功能,但我了解到它们都有一个“配额”系统,用户在超过限额后必须支付打印费用。恐怕这对我不起作用 我也看到了一个类似问题的答案 谢天谢地,这个答案对我帮助很大,只是我不知道如何限制或限制用户打印超出指定数字的内容 我也读过很多答案,说
非常感谢您的帮助。这是一个粗糙的解决方案,但这会增加打印数量的限制 将以下内容放入本工作簿中:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Cancel = True
If Cancel = True Then
MsgBox "Please use the print button on Sheet1."
End If
End Sub
添加一个CommandButton
并将其重命名为PrintButton
,然后将此子例程(以及附带的函数)插入到模块中
Private Sub PrintButton_Click()
On Error Resume Next
Application.EnableEvents = False
If (CanWePrint(4)) Then
ActiveSheet.PrintOut
Else
MsgBox ("Sorry this is the maximum number of prints for this document!")
End If
Application.EnableEvents = True
On Error GoTo 0
End Sub
Function CanWePrint(ByVal MaxPrintVal As Integer) As Boolean
Dim CurrentPrintCount As String, SecretFile As String
'PLEASE CHANGE TO YOUR "SECRET" TXT FILE NAME AND LOCATION!
SecretFile = "C:\Users\Matt\Documents\countPrint.txt"
CurrentPrintCount = GetCount(SecretFile)
If (CurrentPrintCount < MaxPrintVal) Then
Call UpdatePrintCount(CurrentPrintCount, SecretFile)
CanWePrint = True
Else
CanWePrint = False
End If
End Function
Function GetCount(ByVal SecretFile As String) As Integer
Dim nSourceFile As Integer
Dim sText As String
Close
nSourceFile = FreeFile
Open SecretFile For Input As #nSourceFile
sText = Input$(LOF(1), 1)
Close
GetCount = CInt(sText)
End Function
Sub UpdatePrintCount(ByVal CurrentVal As Integer, ByVal SecretFile As String)
Dim sBuf As String
Dim sTemp As String
Dim iFileNum As Integer
iFileNum = FreeFile
Open SecretFile For Input As iFileNum
Do Until EOF(iFileNum)
Line Input #iFileNum, sBuf
sTemp = sTemp & sBuf & vbCrLf
Loop
Close iFileNum
sTemp = Replace(sTemp, CurrentVal, CurrentVal + 1)
iFileNum = FreeFile
Open sFileName For Output As iFileNum
Print #iFileNum, sTemp
Close iFileNum
End Sub
Private子打印按钮\u Click()
出错时继续下一步
Application.EnableEvents=False
如果(可以打印(4)),则
ActiveSheet.PrintOut
其他的
MsgBox(“抱歉,这是此文档的最大打印数!”)
如果结束
Application.EnableEvents=True
错误转到0
端接头
函数CanWePrint(ByVal MaxPrintVal为整数)为布尔值
Dim CurrentPrintCount作为字符串,SecretFile作为字符串
'请更改为您的“机密”TXT文件名和位置!
SecretFile=“C:\Users\Matt\Documents\countPrint.txt”
CurrentPrintCount=GetCount(SecretFile)
如果(CurrentPrintCount
这是干什么的
此代码将禁用该工作簿Excel中的标准打印选项。通过添加命令按钮
可以创建一个手动打印选项,该选项将检查存储在.txt
文件中的打印计数,这意味着文档可以关闭和重新打开,并且仍然只能打印4次
你需要做什么
- 在与此文档相同的计算机上创建新的txt文件,并在
中更新上面代码中的路径CanWePrint
- 手动更改
文件中的值.txt
- 不使用VBA保存工作簿
- 禁用VBA
谢谢大家! 非常感谢你,马特@塞普拉,不客气。如果这解决了您的问题,请不要忘记将问题标记为已完成!:-)是的,请看一看我的答案,然后告诉我是否足够好,再次感谢。