Log abrir y cerrar un excel en red
Necesitaría una macro que cree un log cuando alguien abra y cierre un archivo excel en modo escritura que esta en una carpeta en red.
He encontrado una macro en la red, pero esta añade al log quien y cuando abre y cierra el archivo tanto para lectura como para escritura y no se como hacer que sea solo escritura. Adjunto el código:
in this workbook:
Private Sub Workbook_Open()
Call Iniciar
End Sub
'
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call Iniciar
End Sub
en modulo de clase:
Public WithEvents AppEvents As Application
'
Private Sub AppEvents_WorkbookBeforeClose(ByVal Wb As Workbook, Cancel As Boolean)
Call ActualizarLogSalida(Wb)
End Sub
'
Private Sub AppEvents_WorkbookOpen(ByVal Wb As Excel.Workbook)
Call ActualizarLog(Wb)
End Sub
En un modulo:
Dim AppObject As New Clase1
'
Sub Iniciar()
Set AppObject.AppEvents = Application
End Sub
'
Sub ActualizarLog(Wb)
Dim txt As String
Dim Fname As String
On Error Resume Next
txt = Wb.ReadOnly.FullName
txt = txt & ", " & Date & ", " & Time
txt = txt & ", " & Application.UserName
txt = txt & ", " & "Abierto"
Fname = Application.ActiveWorkbook.Path & "\logfile.csv"
Open Fname For Append As #1
Print #1, txt
Close #1
'MsgBox txt
On Error GoTo 0
End Sub
'
Sub ActualizarLogSalida(Wb)
Dim txt As String
Dim Fname As String
On Error Resume Next
txt = Wb.ReadOnly.FullName
txt = txt & ", " & Date & ", " & Time
txt = txt & ", " & Application.UserName
txt = txt & ", " & "Cerrado"
Fname = Application.ActiveWorkbook.Path & "\logfile.csv"
Open Fname For Append As #1
Print #1, txt
Close #1
'MsgBox txt
On Error GoTo 0
End Sub