Check the number of copies that were printed

4

Hello, I have a table that, when printed, generates a record in a txt, telling the user who printed it, which machine, which printer, which document, and when. But I would like to also record the number of copies, but I have no idea how.

Code that takes information from your computer:

Declare Function GetComputerName& Lib "kernel32" Alias "GetComputerNameA" (ByVal lbbuffer As String, nSize As Long)
Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" (ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long) As Long

Function deMAQUINA() As String
Dim Buffer As String * 256
Dim BuffLen As Long
Dim lngX As Long
Dim strCompName As String
BuffLen = 255
If GetComputerName(Buffer, BuffLen) Then deMAQUINA = Left(Buffer, BuffLen)
End Function

Function deUSUARIO() As String
Dim Buffer As String * 256
Dim BuffLen As Long
BuffLen = 256
If GetUserName(Buffer, BuffLen) Then deUSUARIO = Left(Buffer, BuffLen - 1)
End Function

Code that registers:

 Private Sub Workbook_BeforePrint(Cancel As Boolean)

    Dim vUsuario As String, vMaquina As String
    vUsuario = deUSUARIO()
    vMaquina = deMAQUINA()

    Open "\Caminho\do\arquivo.txt" For Append As #2

        Print #2, "O usuário: " & vUsuario & " | pela Máquina: " & vMaquina & " | pela impressora: " & ActivePrinter & " | Imprimiu o documento " & ActiveWorkbook.Name & "| no dia: " & Now

    Close #2

    Open ActiveWorkbook.Path & "\OBSOLETO\" & Left(ActiveWorkbook.Name, 8) & ".txt" For Append As #3

        Print #3, "O usuário: " & vUsuario & " | pela Máquina: " & vMaquina & " | pela impressora: " & ActivePrinter & " | Imprimiu o documento " & ActiveWorkbook.Name & "| no dia: " & Now

    Close #3

End Sub

If anyone knows, could you please help?

    
asked by anonymous 29.06.2017 / 18:41

1 answer

1
Private Sub Workbook_BeforePrint(Cancel As Boolean) 
If ActiveSheet.CodeName = "Sheet1" Then 
    With Sheet1.Range("A1") 
        Select Case .Value 
        Case Is > 0 
            .Range("A1").Value = .Range("A1") + 1 

        Case Else ' cell is empty
            .Range("A1").Value = 1 

        End Select 
    End With 
End If 
End Sub 

You can use a counter and increment a cell with each new impression. check if you can with this code implement your!

    
06.07.2017 / 17:31