PC Review


Reply
Thread Tools Rate Thread

Auto_open User Name Log

 
 
mrsviqt
Guest
Posts: n/a
 
      29th May 2009
I would like a macro that logs the username and date/time the file was opened
and sends it to a txt file that is on my C: drive. I can get it to work for
myself, but if another user opens the file, it doesn't log it. Is there a
way to run the macro as soon as the other user opens the file? I thought I
had it down pat because it works for myself, but discovered it was wrong when
a coworker opened and closed the file for me.
Here is the code I have so far:
Sub Auto_Open()
LogInformation ThisWorkbook.Name & " opened by " & _
Application.UserName & " " & Format(Date, "yyyy-mm-dd") & " " & _
Format(Time, "hh:mm")

End Sub

Sub LogInformation(LogMessage As String)
Const LogFileName As String = "C:\Data\MyLog.txt"
Dim FileNum As Integer
FileNum = FreeFile
' next file number
Open LogFileName For Append As #FileNum
' creates the file if it doesn't exist
Print #FileNum, LogMessage
' write information at the end of the text file
Close #FileNum ' close the file
End Sub

Thank you in advance for your assistance!





 
Reply With Quote
 
 
 
 
Bob Bridges
Guest
Posts: n/a
 
      29th May 2009
This is maybe too obvious, but since it's another user, is he on another
machine? If so, it's probably logging it just fine -- to C:\Data\MyLog.txt,
on his machine in other words.

--- "mrsviqt" wrote:
> I would like a macro that logs the username and date/time the file was opened
> and sends it to a txt file that is on my C: drive. I can get it to work for
> myself, but if another user opens the file, it doesn't log it. Is there a
> way to run the macro as soon as the other user opens the file? I thought I
> had it down pat because it works for myself, but discovered it was wrong when
> a coworker opened and closed the file for me.
> Here is the code I have so far:
> Sub Auto_Open()
> LogInformation ThisWorkbook.Name & " opened by " & _
> Application.UserName & " " & Format(Date, "yyyy-mm-dd") & " " & _
> Format(Time, "hh:mm")
> End Sub
>
> Sub LogInformation(LogMessage As String)
> Const LogFileName As String = "C:\Data\MyLog.txt"
> Dim FileNum As Integer
> FileNum = FreeFile
> ' next file number
> Open LogFileName For Append As #FileNum
> ' creates the file if it doesn't exist
> Print #FileNum, LogMessage
> ' write information at the end of the text file
> Close #FileNum ' close the file
> End Sub
>
> Thank you in advance for your assistance!
>
>
>
>
>

 
Reply With Quote
 
Patrick Molloy
Guest
Posts: n/a
 
      1st Jun 2009
its unlikely that another PC will have access to your C drive. If thats
possible, have a word with your netwirk admin team cos thats a BAD thing!

suggest that you create a folder on a shared drive that all users can write
to, but can't delete from.

"mrsviqt" <(E-Mail Removed)> wrote in message
news:73521595-E073-443E-BCC8-(E-Mail Removed)...
> I would like a macro that logs the username and date/time the file was
> opened
> and sends it to a txt file that is on my C: drive. I can get it to work
> for
> myself, but if another user opens the file, it doesn't log it. Is there a
> way to run the macro as soon as the other user opens the file? I thought
> I
> had it down pat because it works for myself, but discovered it was wrong
> when
> a coworker opened and closed the file for me.
> Here is the code I have so far:
> Sub Auto_Open()
> LogInformation ThisWorkbook.Name & " opened by " & _
> Application.UserName & " " & Format(Date, "yyyy-mm-dd") & " " & _
> Format(Time, "hh:mm")
>
> End Sub
>
> Sub LogInformation(LogMessage As String)
> Const LogFileName As String = "C:\Data\MyLog.txt"
> Dim FileNum As Integer
> FileNum = FreeFile
> ' next file number
> Open LogFileName For Append As #FileNum
> ' creates the file if it doesn't exist
> Print #FileNum, LogMessage
> ' write information at the end of the text file
> Close #FileNum ' close the file
> End Sub
>
> Thank you in advance for your assistance!
>
>
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
AUTO_OPEN Bob Barnes Microsoft Excel Misc 2 6th Feb 2008 03:03 AM
hide/protext auto_open code so user can't prevent it from running =?Utf-8?B?U2NvdHQ=?= Microsoft Excel Programming 4 18th May 2007 04:40 PM
Need to run auto_open before user disables macros at startup pinkfloydfan Microsoft Excel Programming 2 20th Oct 2006 11:20 AM
Auto_open dan Microsoft Excel Misc 7 21st May 2006 10:41 AM
Auto_open Tom Microsoft Access 2 6th Jan 2005 04:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:36 AM.