Track opening time and closing time ofworkbook

EinarOSies

Board Regular
Joined
Feb 15, 2021
Messages
61
Office Version
  1. 2019
Platform
  1. Windows
Please I may want a code to calculate the time I used in working with a workbook. The details are when I open the workbook it stores it in a cell then when closing it stores it in another cell then calculate the difference between the my opening time and closing time and present it to me with a message box of the difference or the amount of time I used working with the workbook. Please thanks
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
After pasting the and while debugging it gives me an error that " The code in this project must be updated for use on 64-bit systems. Please review and update Declare statements and then mark them with the PtrSafe attribute". Is there anyway I can get around it to work both on 32-bit machines and 64-bit machines.
Thanks Einar
 
Upvote 0
After pasting the and while debugging it gives me an error that " The code in this project must be updated for use on 64-bit systems. Please review and update Declare statements and then mark them with the PtrSafe attribute". Is there anyway I can get around it to work both on 32-bit machines and 64-bit machines.
Thanks Einar
If you go to VBA Editor, you can see that line that call Function such as

Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" ( _
ByVal lpBuffer As String, _
nSize As Long) As Long

is red in color.

You just need add PtrSafe

Private Declare PtrSafe Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" ( _
ByVal lpBuffer As String, _
nSize As Long) As Long

Do this for all those red color line. They are usually the Private Declare Function. Then it should be compatible for bot 32 and 64-bit as far as I know
 
Upvote 0
Please when I run the code it gives me a run-time error '1004'. "The cell or chart you're trying to change, unprotected the sheet. You might be requested to enter a password"
Behind the code for the workbook on opening it protects all worksheet. Please how can your code work at the same time protect my workbook
 
Upvote 0
You meant when upon opening workbook, it protects all worksheet? I guess you have to exclude that Audit xlVeryHidden worksheet. No one can unhide it except through VBA.
 
Upvote 0
Yes I tried I have tried that and it still gives me that error even stopping all my macros in the workbook open event. Any additional help
 
Upvote 0
Yes I tried I have tried that and it still gives me that error even stopping all my macros in the workbook open event. Any additional help
Sorry. I've never tried this before. I just copy the code on new workbook and it seems that the sheets Audit was not created as believed. That caused an error. I made some change and this seems to work.

on this part

VBA Code:
If Err.Number = 9 Then
        Set WS = Me.Worksheets.Add(before:=1)
        WS.Name = "Audit"
    End If

change to

VBA Code:
If Err.Number = 9 Then
    Set WS = Sheets.Add(Before:=Sheets(1))
    WS.Name = "Audit"
End If
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top