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?