验证具有打印件的份数

时间:2017-07-03 11:56:54

标签: vba excel-vba printing excel

我有一张表,打印时会在txt中生成一条记录,告诉用户打印它,在哪台机器上打印,哪台打印机,文件是什么以及何时打印。但我想记录副本的数量,但我不知道如何。

从计算机获取信息的代码:

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

注册的代码:

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

如果有人知道,请帮忙吗?

对不起,我不得不翻译,为什么没有人知道如何回应服务器BR

0 个答案:

没有答案