count time

M

Mark

I looking for VBA code produce: write to file.txt working
life workbook by user.

I have only code with open file time:

Open ThisWorkbook.Path & "\file.txt" For Append As #1
Print #1, Now, Application.UserName,
Application.ActiveWorkbook.Name
Close #1

How and where i write variable and remain code to show
total time usage by one user?

Regards
Mark
 
T

Tom Ogilvy

Put it in the workbook_before close event. Unless you store the opening
time somewhere, I believe you would need to read the time from the file you
wrote with your existing code, then subtract it from "now".
 
M

Mark

Hi Tom!
As would you see complete code?
"Now" return system data and time how count total usage
time (e.g. in minutes)?
Best regards
Mark
 
T

Tom Ogilvy

in the ThisWorkbook module

at the top declare a public variable

Public StartTime as Date

then put the code

Private Sub Workbook_Open()
StartTime = Now
Open ThisWorkbook.Path & "\file.txt" For Append As #1
Print #1, StartTime, Application.UserName, _
Application.ActiveWorkbook.Name
Close #1
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Open ThisWorkbook.Path & "\file.txt" For Append As #1
Print #1, Now - StartTime, Application.UserName, _
Application.ActiveWorkbook.Name, "Close"
Close #1
End Sub

Untested, but this should get you close.
 
B

Bob Phillips

Mark,

Total minutes

totalMins = (Now - Date)*1440

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
G

Guest

Why not just stick the open file and write time in workbooks auto_open sub and the close time in the auto_close sub?

Mark
 
M

Mark

Thanks Tom for help!

Regards
Mark
-----Original Message-----
in the ThisWorkbook module

at the top declare a public variable

Public StartTime as Date

then put the code

Private Sub Workbook_Open()
StartTime = Now
Open ThisWorkbook.Path & "\file.txt" For Append As #1
Print #1, StartTime, Application.UserName, _
Application.ActiveWorkbook.Name
Close #1
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Open ThisWorkbook.Path & "\file.txt" For Append As #1
Print #1, Now - StartTime, Application.UserName, _
Application.ActiveWorkbook.Name, "Close"
Close #1
End Sub

Untested, but this should get you close.

--
Regards,
Tom Ogilvy





.
 
M

Mark

THanks Bob for your reply about minutes subject.
-----Original Message-----
Mark,

Total minutes

totalMins = (Now - Date)*1440

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)




.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top