Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 160
Default Creating a Log

I have a spreadsheet that demonstrated excess inventory. I need to be able to
keep track of who is using this spreadsheet... so I came up with the idea of
capturing some data (date, user, full path, how long they had it open) and
writing it to another spreadsheet on a network drive that everyone has access
to (P:\)
The code (below) works perfectly in my testing... right up until I tested
having 2 people open the file at the same time and close the workbook at the
same time. When that happened... my ExcessLog.xls file returned an "unable to
read file" error. I have not been able to open it since. Does anyone know
what this happened? Have any suggestions for making this work? Have a better
solution for keeping track of who opens/uses a spreadsheet?

Here is the code, which is in the ThisWorkbook object:

'** When workbook is opened triggers the start timer. When the workbook is
closed it captures the user, path, stop time after validating that the user
has access to the P:\

Dim TStart As Long 'Timer - Start
Dim TStop As Long 'Timer - Stop
Dim MyPath As String 'Full Path of Workbook
Dim PW As String 'Sheet Protection Password
Dim DV As String 'Dialog Value for MsgBox
Dim x As Long
Private Sub Workbook_BeforeClose(Cancel As Boolean)
PW = "test"
If Dir("P:\Permanent_Data\Patrick\Excess Inventory\") < "" Then
Application.ScreenUpdating = False
MyPath = Application.ActiveWorkbook.FullName
ChDir "P:\Temporary_Data_60_Days\Patrick\Logs"
Workbooks.Open
Filename:="P:\Temporary_Data_60_Days\Patrick\Logs\ ExcessLog.xls"
Workbooks("ExcessLog.xls").Sheets("UserLog").Unpro tect PW
Range("A2").Select
x = 2
'** Get to empty row
While Trim(ActiveCell.Offset(0, 0).Value) < ""
ActiveCell.Offset(1, 0).Select
x = x + 1
Wend
TStop = Timer
Range("A" & x).Value = Date
Range("B" & x).Value = MyPath
Range("C" & x).Value = Application.UserName
Range("D" & x).Value = ((TStop - TStart) / 60)
Workbooks("ExcessLog.xls").Sheets("UserLog").Prote ct PW
Workbooks("ExcessLog.xls").Save
Workbooks("ExcessLog.xls").Close
Application.ScreenUpdating = True
Else
DV = MsgBox("Contact the HelpDesk and request access to the P:\",
vbOKOnly, "Slight Problem...")
End If
End Sub
Public Sub Workbook_Open()
TStart = Timer
End Sub


Any assistance/feedback is greatly appreciated! patrick
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Creating a Log

Excel does not deal with concurency at all well. You will have a lot of
difficulty avoiding collisions. Do you have MS Access on your computer. If so
Access is ideal for tracking this kind of info without any of the concurrency
issues. What you want to do is really pretty easy to impliment with ADO
recordsets. Let me know if you want to follow this path...

"Patrick" wrote:

I have a spreadsheet that demonstrated excess inventory. I need to be able to
keep track of who is using this spreadsheet... so I came up with the idea of
capturing some data (date, user, full path, how long they had it open) and
writing it to another spreadsheet on a network drive that everyone has access
to (P:\)
The code (below) works perfectly in my testing... right up until I tested
having 2 people open the file at the same time and close the workbook at the
same time. When that happened... my ExcessLog.xls file returned an "unable to
read file" error. I have not been able to open it since. Does anyone know
what this happened? Have any suggestions for making this work? Have a better
solution for keeping track of who opens/uses a spreadsheet?

Here is the code, which is in the ThisWorkbook object:

'** When workbook is opened triggers the start timer. When the workbook is
closed it captures the user, path, stop time after validating that the user
has access to the P:\

Dim TStart As Long 'Timer - Start
Dim TStop As Long 'Timer - Stop
Dim MyPath As String 'Full Path of Workbook
Dim PW As String 'Sheet Protection Password
Dim DV As String 'Dialog Value for MsgBox
Dim x As Long
Private Sub Workbook_BeforeClose(Cancel As Boolean)
PW = "test"
If Dir("P:\Permanent_Data\Patrick\Excess Inventory\") < "" Then
Application.ScreenUpdating = False
MyPath = Application.ActiveWorkbook.FullName
ChDir "P:\Temporary_Data_60_Days\Patrick\Logs"
Workbooks.Open
Filename:="P:\Temporary_Data_60_Days\Patrick\Logs\ ExcessLog.xls"
Workbooks("ExcessLog.xls").Sheets("UserLog").Unpro tect PW
Range("A2").Select
x = 2
'** Get to empty row
While Trim(ActiveCell.Offset(0, 0).Value) < ""
ActiveCell.Offset(1, 0).Select
x = x + 1
Wend
TStop = Timer
Range("A" & x).Value = Date
Range("B" & x).Value = MyPath
Range("C" & x).Value = Application.UserName
Range("D" & x).Value = ((TStop - TStart) / 60)
Workbooks("ExcessLog.xls").Sheets("UserLog").Prote ct PW
Workbooks("ExcessLog.xls").Save
Workbooks("ExcessLog.xls").Close
Application.ScreenUpdating = True
Else
DV = MsgBox("Contact the HelpDesk and request access to the P:\",
vbOKOnly, "Slight Problem...")
End If
End Sub
Public Sub Workbook_Open()
TStart = Timer
End Sub


Any assistance/feedback is greatly appreciated! patrick

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 253
Default Creating a Log

Hi Patrick,

Just check if the file if not open in read-only mode :
.....
boFileOpen = False
Do
Set wbDest = Workbooks.Open("QuestionnaireDB.xls", , , , conPW_DB)
If wbDest.ReadOnly = True Then
wbDest.Close
Application.Wait (Now + TimeValue("00:00:01"))
Else: boFileOpen = True
End If
Loop Until boFileOpen = True
......

Regards,

JY

"Patrick" wrote in message
...
I have a spreadsheet that demonstrated excess inventory. I need to be able

to
keep track of who is using this spreadsheet... so I came up with the idea

of
capturing some data (date, user, full path, how long they had it open) and
writing it to another spreadsheet on a network drive that everyone has

access
to (P:\)
The code (below) works perfectly in my testing... right up until I tested
having 2 people open the file at the same time and close the workbook at

the
same time. When that happened... my ExcessLog.xls file returned an "unable

to
read file" error. I have not been able to open it since. Does anyone know
what this happened? Have any suggestions for making this work? Have a

better
solution for keeping track of who opens/uses a spreadsheet?

Here is the code, which is in the ThisWorkbook object:

'** When workbook is opened triggers the start timer. When the workbook is
closed it captures the user, path, stop time after validating that the

user
has access to the P:\

Dim TStart As Long 'Timer - Start
Dim TStop As Long 'Timer - Stop
Dim MyPath As String 'Full Path of Workbook
Dim PW As String 'Sheet Protection Password
Dim DV As String 'Dialog Value for MsgBox
Dim x As Long
Private Sub Workbook_BeforeClose(Cancel As Boolean)
PW = "test"
If Dir("P:\Permanent_Data\Patrick\Excess Inventory\") < "" Then
Application.ScreenUpdating = False
MyPath = Application.ActiveWorkbook.FullName
ChDir "P:\Temporary_Data_60_Days\Patrick\Logs"
Workbooks.Open
Filename:="P:\Temporary_Data_60_Days\Patrick\Logs\ ExcessLog.xls"
Workbooks("ExcessLog.xls").Sheets("UserLog").Unpro tect PW
Range("A2").Select
x = 2
'** Get to empty row
While Trim(ActiveCell.Offset(0, 0).Value) < ""
ActiveCell.Offset(1, 0).Select
x = x + 1
Wend
TStop = Timer
Range("A" & x).Value = Date
Range("B" & x).Value = MyPath
Range("C" & x).Value = Application.UserName
Range("D" & x).Value = ((TStop - TStart) / 60)
Workbooks("ExcessLog.xls").Sheets("UserLog").Prote ct PW
Workbooks("ExcessLog.xls").Save
Workbooks("ExcessLog.xls").Close
Application.ScreenUpdating = True
Else
DV = MsgBox("Contact the HelpDesk and request access to the P:\",
vbOKOnly, "Slight Problem...")
End If
End Sub
Public Sub Workbook_Open()
TStart = Timer
End Sub


Any assistance/feedback is greatly appreciated! patrick



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 160
Default Creating a Log

Perfect! Thank you JY!

"Jean-Yves" wrote:
Hi Patrick,
Just check if the file if not open in read-only mode :
......
boFileOpen = False
Do
Set wbDest = Workbooks.Open("QuestionnaireDB.xls", , , , conPW_DB)
If wbDest.ReadOnly = True Then
wbDest.Close
Application.Wait (Now + TimeValue("00:00:01"))
Else: boFileOpen = True
End If
Loop Until boFileOpen = True
.......

Regards,

JY


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 160
Default Creating a Log

I do have Access and I am interested. Until this point my company has been
using a different relational database product... but it looks like we are
heading toward Access. I should probably learn to use it... and this logging
task will force me to get off my rump and finally do it (with some help :)

"Jim Thomlinson" wrote:

Excel does not deal with concurency at all well. You will have a lot of
difficulty avoiding collisions. Do you have MS Access on your computer. If so
Access is ideal for tracking this kind of info without any of the concurrency
issues. What you want to do is really pretty easy to impliment with ADO
recordsets. Let me know if you want to follow this path...

"Patrick" wrote:

I have a spreadsheet that demonstrated excess inventory. I need to be able to
keep track of who is using this spreadsheet... so I came up with the idea of
capturing some data (date, user, full path, how long they had it open) and
writing it to another spreadsheet on a network drive that everyone has access
to (P:\)
The code (below) works perfectly in my testing... right up until I tested
having 2 people open the file at the same time and close the workbook at the
same time. When that happened... my ExcessLog.xls file returned an "unable to
read file" error. I have not been able to open it since. Does anyone know
what this happened? Have any suggestions for making this work? Have a better
solution for keeping track of who opens/uses a spreadsheet?

Here is the code, which is in the ThisWorkbook object:

'** When workbook is opened triggers the start timer. When the workbook is
closed it captures the user, path, stop time after validating that the user
has access to the P:\

Dim TStart As Long 'Timer - Start
Dim TStop As Long 'Timer - Stop
Dim MyPath As String 'Full Path of Workbook
Dim PW As String 'Sheet Protection Password
Dim DV As String 'Dialog Value for MsgBox
Dim x As Long
Private Sub Workbook_BeforeClose(Cancel As Boolean)
PW = "test"
If Dir("P:\Permanent_Data\Patrick\Excess Inventory\") < "" Then
Application.ScreenUpdating = False
MyPath = Application.ActiveWorkbook.FullName
ChDir "P:\Temporary_Data_60_Days\Patrick\Logs"
Workbooks.Open
Filename:="P:\Temporary_Data_60_Days\Patrick\Logs\ ExcessLog.xls"
Workbooks("ExcessLog.xls").Sheets("UserLog").Unpro tect PW
Range("A2").Select
x = 2
'** Get to empty row
While Trim(ActiveCell.Offset(0, 0).Value) < ""
ActiveCell.Offset(1, 0).Select
x = x + 1
Wend
TStop = Timer
Range("A" & x).Value = Date
Range("B" & x).Value = MyPath
Range("C" & x).Value = Application.UserName
Range("D" & x).Value = ((TStop - TStart) / 60)
Workbooks("ExcessLog.xls").Sheets("UserLog").Prote ct PW
Workbooks("ExcessLog.xls").Save
Workbooks("ExcessLog.xls").Close
Application.ScreenUpdating = True
Else
DV = MsgBox("Contact the HelpDesk and request access to the P:\",
vbOKOnly, "Slight Problem...")
End If
End Sub
Public Sub Workbook_Open()
TStart = Timer
End Sub


Any assistance/feedback is greatly appreciated! patrick

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
creating a pdf Andrew R Excel Discussion (Misc queries) 4 September 19th 06 08:21 PM
Really need help creating pop ups mward77095 Excel Discussion (Misc queries) 3 May 8th 06 09:34 PM
Creating ActualSelf Excel Discussion (Misc queries) 1 October 20th 05 08:03 PM
Creating add-ins jomni[_2_] Excel Programming 2 April 1st 04 04:01 AM
Help with creating a VBA paritoshmehta[_2_] Excel Programming 7 March 6th 04 01:21 PM


All times are GMT +1. The time now is 07:45 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"