Option Explicit
' global constants
Global Const gksPassword = "esunachagar"
Global Const gksPasswordReset = "esunagranchagar"
Global Const gksWSPrintControl = "PrintControl"
Global Const gksRngPrintControl = "PrintControlTable"
Global Const gksWSPattern = "Bill*"
' global declarations
Global grngPC As Range
Global gbPrintEnabled As Boolean
Sub UpdatePrintControlTable()
' constants
' declarations
Dim c As Range
Dim I As Long, J As Long, A As String
' start
Worksheets(gksWSPrintControl).Unprotect gksPassword
gbPrintEnabled = False
Set grngPC = Worksheets(gksWSPrintControl).Range(gksRngPrintControl)
J = 0
' process
For I = 1 To Worksheets.Count
With Worksheets(I)
A = .Name
If A Like gksWSPattern Then
Set c = grngPC.Columns(1).Find(A, grngPC.Cells(1, 1), xlValues, xlWhole)
If c Is Nothing Then
J = J + 1
grngPC.Cells(grngPC.Rows.Count, 1).Offset(J, 0).Value = A
End If
End If
End With
Next I
' end
Set grngPC = Nothing
Worksheets(gksWSPrintControl).Protect gksPassword
Beep
End Sub
Sub ControlPrintCount(pbCancel As Boolean)
' constants
' declarations
Dim c As Range
Dim I As Long, J As Long, A As String
Dim bOk As Boolean
' start
Set grngPC = Worksheets(gksWSPrintControl).Range(gksRngPrintControl)
bOk = True
' process
With ActiveWindow
For I = 1 To .SelectedSheets.Count
With .SelectedSheets(I)
If .Name Like gksWSPattern Then
Set c = grngPC.Columns(1).Find(.Name, grngPC.Cells(1, 1), xlValues, xlWhole)
If CInt(c.Offset(0, 1).Value) <> 0 Then
bOk = False
Exit For
End If
End If
End With
Next I
If Not bOk Then
Do
J = MsgBox("Worksheet " & .SelectedSheets(I).Name & _
" yet printed on " & c.Offset(0, 2).Value & vbCr & vbCr & _
"You must enter the password for additional printing.", _
vbApplicationModal + vbQuestion + vbDefaultButton2 + vbOKCancel, _
"Additional printing dialog")
If J = vbOK Then
A = InputBox("Enter the password:", "Additional printing confirmation")
bOk = (A = gksPassword)
If Not bOk Then
MsgBox "Wrong password!", _
vbApplicationModal + vbCritical + vbOKOnly, "Error"
End If
End If
Loop Until bOk Or J = vbCancel
End If
End With
' end
Set grngPC = Nothing
pbCancel = Not bOk
End Sub
Sub PrintAndSave()
' constants
Const gkbTest = True
' declarations
Dim bCancel As Boolean
' start
UpdatePrintControlTable
' process
ControlPrintCount bCancel
If Not bCancel Then
gbPrintEnabled = True
Worksheets(gksWSPrintControl).Unprotect gksPassword
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Preview:=gkbTest
Worksheets(gksWSPrintControl).Protect gksPassword
gbPrintEnabled = False
ActiveWorkbook.Save
End If
' end
Beep
End Sub
Sub ResetAllCounts()
' constants
' declarations
Dim J As Integer, A As String, bOk As Boolean
' start
Do
J = MsgBox("You must enter the password to reset print counts.", _
vbApplicationModal + vbInformation + vbDefaultButton2 + vbOKCancel, _
"Reset print counts dialog")
If J = vbOK Then
A = InputBox("Enter the password:", "Reset print counts confirmation")
bOk = (A = gksPasswordReset)
If Not bOk Then
MsgBox "Wrong password!", _
vbApplicationModal + vbCritical + vbOKOnly, "Error"
End If
End If
Loop Until bOk Or J = vbCancel
If Not bOk Then Exit Sub
Worksheets(gksWSPrintControl).Unprotect gksPassword
Set grngPC = Worksheets(gksWSPrintControl).Range(gksRngPrintControl)
' process
With grngPC
Range(.Cells(2, 2), .Cells(.Rows.Count, .Columns.Count)).ClearContents
End With
' end
Set grngPC = Nothing
Worksheets(gksWSPrintControl).Protect gksPassword
Beep
End Sub