Add code in the Workbook using a macro

0

I have a code that registers who prints the document, but I have a thousand documents and I have to insert the code, I already have the code to put modules, but I need one to put in the Workbook to work when printing, but I can not find how.

Private Sub Workbook_BeforePrint(Cancel As Boolean)

On Error Resume Next

Dim revisão As Integer
revisão = 0
Dim vUsuario As String, vMaquina As String
vUsuario = deUSUARIO()
vMaquina = deMAQUINA()

Open "\CAMINHO\DO\ARQUIVO\" & Right(Left(ActiveWorkbook.Name, 8), 4) & ".txt" For Input As #1

Line_ = 0

Do Until EOF(1)

    Line Input #1, Text

    Line_ = Line_ + 1

    If Text = "" Then

        Exit Do

    End If

    revisão = Left(Text, 3)

Loop

Close #1

Open "\CAMINHO\DO\ARQUIVO\" & Right(Left(ActiveWorkbook.Name, 8), 4) & ".txt" For Append As #2

If revisão <= 9 Then

    Print #2, "0" & (revisão + 1) & " - O usuário: " & vUsuario & " - " & "pela Máquina: " & vMaquina & " - " & "Imprimiu este documento dia: " & Now

Else

    If revisão >= 10 Then

        Print #2, (revisão + 1) & " - O usuário: " & vUsuario & " - " & "pela Máquina: " & vMaquina & " - " & "Imprimiu este documento dia: " & Now

    End If

End If

Close #2

End Sub
    
asked by anonymous 04.04.2017 / 14:54

1 answer

0

I found the answer.

Set WECodeMod2 = ActiveWorkbook.VBProject.VBComponents("EstaPasta_de_trabalho").CodeModule

Open "c:\CAMINHO\DO\ARQUIVO.txt" For Input As #2

  Line_1 = 0

  Do Until EOF(2)

    Line Input #2, text_1

    Line_1 = Line_1 + 1

    WECodeMod2.InsertLines Line_1, text_1

  Loop

Close #2
    
06.04.2017 / 16:28