Home |
Search |
Today's Posts |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Maybe something like:
Option Explicit Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _ "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long Function fOSUserName() As String ' Returns the network login name Dim lngLen As Long, lngX As Long Dim strUserName As String strUserName = String$(254, 0) lngLen = 255 lngX = apiGetUserName(strUserName, lngLen) If lngX < 0 Then fOSUserName = Left$(strUserName, lngLen - 1) Else fOSUserName = "" End If End Function Sub auto_open() If LogTheData(myStr:="Open ") = False Then MsgBox "Error with open logging--call me @ ####" End If End Sub Sub Auto_Close() If LogTheData(myStr:="Close") = False Then MsgBox "Error with open logging--call me @ ####" End If End Sub Function LogTheData(myStr As String) As Boolean Dim myLogName As String Dim FileNum As Long myLogName = ThisWorkbook.FullName & "_Log.txt" On Error GoTo ErrHandler: FileNum = FreeFile Close FileNum 'just in case Open myLogName For Append As #FileNum Print #FileNum, myStr _ & vbTab & ThisWorkbook.FullName _ & vbTab & Format(Now, "mm/dd/yyyy--hh:mm:ss") _ & vbTab & Application.UserName _ & vbTab & fOSUserName Close #FileNum LogTheData = True 'ok Exit Function ErrHandler: Err.Clear LogTheData = False 'faile End Function ===== The log file has to be on a server that everyone can write to. You may want to change the location of the file to something that only you know about, but everyone can write. And you could add as much info as you want to that print command. I like it to be a single line so that I can import it to excel. Every so often, I can clean up the file--just don't lock it up so the logging fails <vbg. Ps. I think I would move the log file to a common folder. Then I could look at this log to see if there is anyone who is running their own copy of the workbook. (That was a big problem where I worked with one of our pricing workbooks.) The official workbook would be updated, but people would be using their own copy. So I'd look at the log (not based on the workbook's fullname) and ask them to destroy their copies and explain why. The second time, I'd visit their boss and explain to them that so-and-so was using an out of date workbook and may be providing the customers with out of date prices (and short changing us). myLogName = ThisWorkbook.FullName & "_Log.txt" would become: myLogName = "\\server\sharename\Pricingworkbook" & "_Log.txt" Alberta Rose wrote: Hi Dave. Could you explain to me how to record this to a text file? "Dave Peterson" wrote: If I were a user of this workbook, I'd be worried--even if I'm not the offender. If you save that workbook that hasn't been touched in 10 minutes, how do you know what you're saving? If that user did something very bad (destroying lots of data or deleting lots of sheets--either by mistake or on purpose (wanting to save it as a new name)), then doesn't saving it just make matters worse? And if you think you can close without saving, I'd hate to be the user who made an hours worth of intricate changes only to lose them because I got a phone call. Heck, I'd hate to be the developer of that ontime procedure when the user complains that he or she didn't do the damage--the developer did. Personally, I think that this is a training issue. You have to get the users on board to make changes and get out. Even better would be to use a different application--one that supports multiple concurrent users (Access or any real database program????). That said, I used to have the same problem. Instead of closing the file automatically, I'd write a record to a text file on a server that was open to everyone (but no one knew about!) whenever any opened the workbook or closed it. Then I'd just open that text file (readonly mode!) to see the last person to open without closing. Alberta Rose wrote: At times someone in our office has a certain file open to which others need access. If the person hasn't made changes in 10 minutes, I'd like the file to save and close automatically after this time period. I've tried a couple of suggestions on this site, but not working. Any help? -- Dave Peterson -- Dave Peterson |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Close file when inactive for 10 minutes. | Excel Programming | |||
Close all inactive workbooks without saving | Excel Programming | |||
Close excel when inactive | Excel Programming | |||
Option in Excel to save a close a workbook inactive for 5 minutes | Excel Discussion (Misc queries) | |||
Inactive close | Excel Programming |