ich habe ein Makro, das bei bestimmten Aktionen ein Logfile erstellt und in einem definierten Pfad ablegt (s. Code).
Kann mir jemand sagen, was ich hier ändern muss, um folgende Alternative zu ergänzen ?
Falls definierter Pfad (strPath) nicht vorhanden, erstelle kein Logfile.
Sub UnauthorizedActions_Msg()
Dim strPath As String, strEntry As String, strHead As String
Dim FF As Integer
' log file headers
strHead = "Date" & Space$(Len(Format(Date, "YYYY/MM/DD"))) & _
"Time" & Space$(Len(CStr(Time))) & _
"User"
'Pfad & Name der Datei
strPath = Sheets(2).Range("I21") & "Unauthorized-Access.txt" _
' log file content
strEntry = Format(Date, "YYYY/MM/DD") & Space$(2) & _
Time & Space$(2) & _
Environ$("UserName") & Space$(2)
FF = FreeFile
' checks if log file already exists and creates new one if not yet available
If Dir(strPath) = "" Then
Open strPath For Append As #FF
Print #FF, strHead
Close #FF
End If
' writes text in log file
Open strPath For Append As #FF
Print #FF, strEntry
Close #FF
Const bytZeit As Byte = 5 'time limit for automatic closure
Dim objWSH As Object, intMSG As Integer
Set objWSH = CreateObject("WScript.Shell")
intMSG = objWSH.Popup("Unauthorized actions reported - No permissions to save or send file ! _
_
", bytZeit, "Unauthorized Access !", vbCritical)
Set objWSH = Nothing
ActiveWorkbook.Close False
End Sub
VG und vielen Dank im Voraus, Marc