Add code to the Workbook using a macro

Asked

Viewed 89 times

0

I have a code that records who prints the document, but I have a thousand documents and I have to enter the code, I already have the code to put modules, but I need one to put in the workbook to work when you print, but I can’t 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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.