View Single Post
  #4   Report Post  
GWB Direct
 
Posts: n/a
Default

I'll try this approach. The end result will allow me to li,it the amount of
time a user can opn a workbook. How do I add this code to the workbook so it
starts when someone opens the file.
Thanks
--
Gary Baker


"dbaggett" wrote:

I'm not sure if this is what you want but it will give you the amount of time
the book was open and how many times it has been open. It ties up four cells.
You will need to format cells A1:A3 (Custom, h:mm:ss). I'm sure there has got
to be a better way I just don't know it.

Sub Auto_Open()
Dim tm1 As Date
Dim num As Integer
tm1 = Now()
tm1 = Format(Time, ShortTime)
Sheets("Sheet1").Select
Range("A2").Value = tm1
num = Range("B1").Value
Range("B1").Value = num + 1

End Sub

Sub Auto_Close()
Dim tm2 As Date
Dim tm As Date
tm2 = Now()
tm2 = Format(Time, ShortTime)
Sheets("Sheet1").Select
Range("A3").Value = tm2 - Range("A2").Value
tm = Range("A1").Value + Range("A3").Value
Range("A1:A3").ClearContents
Range("A1").Value = tm
Range("A1").Select
ThisWorkbook.Save

End Sub


"GWB Direct" wrote:

When someone opens a workbook it records the day it was opened so I can use
it in a formula.
Example:
User opens on 5-1-05 at 12:00 p.m. = Now ( )
Closes on 5-1-05 at 5:00 pm.
Opens again on 5-2-05 at12:00 p.m.
Closes on 5-2-05 at 2:00 pm
Number of days or hours used = 2 days or 7 hours
Is there a formula that locks the 1st day 5-1-05, 12:00 p.m.
If it is a macro do I need a button to make it work or can I add the code to
an exisiting button or just when the workbook is opened for the first time.
--
Gary Baker