#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default count time

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default count time

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".

--
Regards,
Tom Ogilvy

"Mark" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default count time

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

-----Original Message-----
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".

--
Regards,
Tom Ogilvy

"Mark" wrote in message
...
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



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default count time

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


"Mark" wrote in message
...
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

-----Original Message-----
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".

--
Regards,
Tom Ogilvy

"Mark" wrote in message
...
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



.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default count time

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)

"Mark" wrote in message
...
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

-----Original Message-----
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".

--
Regards,
Tom Ogilvy

"Mark" wrote in message
...
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



.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default count time

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

"Mark" wrote:

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

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default count time

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


"Mark" wrote in message
...
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

-----Original Message-----
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".

--
Regards,
Tom Ogilvy

"Mark" wrote in message
...
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


.



.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default count time

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)

"Mark" wrote in message
...
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

-----Original Message-----
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".

--
Regards,
Tom Ogilvy

"Mark" wrote in message
...
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


.



.

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
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Worksheet Functions 1 May 3rd 08 02:35 PM
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Discussion (Misc queries) 1 May 3rd 08 10:52 AM
Count Employee Work Time - Don't Count Duplicates J Excel Worksheet Functions 3 May 1st 07 10:47 PM
how to count the time ghost Excel Discussion (Misc queries) 1 April 29th 07 06:09 PM
Count Employee Work Time - Don't Double-count Overlapping Apts. J Excel Worksheet Functions 0 April 27th 07 05:52 AM


All times are GMT +1. The time now is 08:52 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"