View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
cht13er cht13er is offline
external usenet poster
 
Posts: 141
Default Who opens my file?

On May 15, 1:51 pm, Geraldine
wrote:
Thanks for the info. Where would the additional code fit into the original
code?

Private 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:\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

"cht13er" wrote:
On May 12, 8:34 pm, Geraldine
wrote:
Madiya,
I was wondering if you could point me in the direction of how to log the
file path or where I can find other logging options?


Thanks for your help, Geraldine


"Madiya" wrote:
On Apr 30, 5:57 pm, cht13er wrote:
On Apr 29, 11:39 am, ryguy7272
wrote:


This method works great:


Private 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:\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


Both macros go into a standard module.
Then, place a text file on your C: drive (in C:, right-click New Text
Document name it 'MyLog').


Regards,
Ryan---
--
RyGuy


"cht13er" wrote:
On Apr 28, 3:23 pm, Ken wrote:
Chris


In similar situations I have created a logging system where certain
events trigger the writing of data to a text file. If all the copies
of your app will be running on a network, and if there is a spot on
the network that all the users have access to, it is pretty easy to
open the text file and write whatever data you are interested in to
the text file. The writing process could be triggered by the file
open event or file close event and simply write the user name and the
time. Below is a sample where logging and the location of the log
file are controlled by variables in named worksheet cells. The Print
line in your case could include the username, time and whatever else
you desire instead of the stuff I have in the example. Also, in your
case you may be better off hardcoding the location of the log file and
eliminating the option to suppress the logging. Unless you have a
particularly slow network, the logging activity should be barely
noticable.


If Range("Enable_logging") = True Then
fName = Range("Path").Value & Range("Log_file").Value
On Error GoTo EndMacro:
fnum = FreeFile
Open fName For Append Access Write As #fnum
Print #fnum, cName, "Created Export file", "with " & x; "
records", , Now
EndMacro:
On Error GoTo 0
Application.ScreenUpdating = True
Close #fnum
End If


You could actually trigger a process that generates an e-mail, and if
the potential users, including bootleg users are not on a network, you
may have to resort to something along that line. If they are
networked though, I supspect you will be happier just tracking
activity and avoiding auto generated e-mail.


Good luck.


Ken
Norfolk, Va


On Apr 28, 1:31 pm, cht13er wrote:


Good day, thanks for your comments and replies!


I've created a large-scale application with Excel VBA and I would like
to keep track of who uses the program. Because there is always the
possibility that someone made a copy of the file and is working off of
their version, creating a list of users on an xlVeryHidden sheet
wouldn't work...because it's hard to know where the original file
ended up.


I would like to know if there is any way to automatically fire off a
quasi-email .... or how in the world I can approach this!


Thanks for your help!


Chris


Thanks for the reply, Ken. I think I'll set it up just as you have
suggested.


Chris- Hide quoted text -


- Show quoted text -


ryguy - The .txt file won't be on my local C drive - but on the
company's network drive. The problem I have is when the network is
unavailable (perhaps no internet connection, perhaps someone pirated a
copy and isn't on our network, etc) ... and trying to decide how to
manage those users, too! But I guess for the short-term I can set up
this writing to a network drive's .txt file ... and if the file is
unavailable just let the program continue.


Thanks


Chris- Hide quoted text -


- Show quoted text -


In the log file, you may also include the information of the current
file path.
With this you will know if the user has his own copy of the file
somewhere else.


Regards,
Madiya


dim strPathName as String
strPathName = "The file location is: " & ThisWorkbook.Path


Does that help?


It would be as follows:

Private Sub Auto_Open()
LogInformation ThisWorkbook.Path & " opened by " & _
Application.UserName & " " & Format(Date, "yyyy-mm-dd") & " " &
Format(Time, "hh:mm")
End Sub