Olá! Dê uma olhada no exemplo que fiz. Qualquer dúvida pergunte.
Private LogFile As String 'Caminho do arquivo de log
Private Const ForReading As Byte = 1
Private Const ForWriting As Byte = 2
Private Const ForAppending As Byte = 8
Private Sub WriteLog(ByVal Number As Long, ByVal Message As String)
Dim FSO As Object, TextFile As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Set TextFile = FSO.OpenTextFile(LogFile, ForAppending, True)
TextFile.WriteLine (Now & vbTab & Number & vbTab & Message)
TextFile.Close
Set TextFile = Nothing
Set FSO = Nothing
End Sub
Private Sub Form_Load() 'Gera um erro pra testar a rotina
LogFile = App.Path & "app.log"
On Error GoTo catch_exception
Dim i As Integer
i = 100 / 0
Exit Sub
catch_exception:
MsgBox ("Atenção houve um erro!" & vbCrLf & _
"Número do erro: " & Err.Number & vbCrLf & _
"Descrição do erro: " & Err.Description)
WriteLog Err.Number, Err.Description
End Sub
Flw!