VBA Log-Datei erstellen

21.08.2014 13:34 | Gajamugan Kandiah | Keine Kommentare

Um einfachen Log-Datei in VBA zu erstellen habe ich was ganz einfaches gesucht. Hab dann per Zufall folgendes entdeckt:

Folgende Funktion im Modul erstellen

Public Function DBPfad() As String 
     DBPfad = Left(CurrentDb.Name, Len(CurrentDb.Name) _ 
                                 - Len(Dir(CurrentDb.Name))) 
 End Function 
 
 Public Sub Log(strLog As String) 
     Dim strFile As String, strMeld$ 
     Dim f As Integer 
 
     strFile = DBPfad & "Logfile.txt" 
     strMeld = "[" & Format(Now, "dd.mm.yyyy hh:nn:ss") & "] " & strLog 
     f = FreeFile 
     Open strFile For Append As #f 
     Print #1, strMeld 
     Close #f 
 End Sub

und an diversen Stellen dann

 Log "Text"

Quelle: http://www.office-loesung.de/ftopic406773_0_0_asc.php

 

Kommentar schreiben

Kommentar

Time limit is exhausted. Please reload CAPTCHA.