Finding the amount of time being used in working with a document

EinarOSies

Board Regular
Joined
Feb 15, 2021
Messages
61
Office Version
  1. 2019
Platform
  1. Windows
I have been working on a code to calculate the amount of time being used when closing a workbook. These are my line of code:
VBA Code:
Sub VBA_Calculate_Minutes_Between_Two_Times()
Dim sTime As Date, eTime As Date
Dim iValue As Integer
Worksheets("OVERALL TOTAL DETAILS").Range("A41").Value2 = sTime
Now() = eTime
iValue = DateDiff("n", sTime, eTime)

MsgBox "The amount of time you used to work is " & iValue, vbInformation, ""
End Sub
The idea of my code is that when I open my workbook it should store the opening time in sheet @OVERALL TOTAL DETAILS cell A41, thus Worksheets("OVERALL TOTAL DETAILS").Range("A41").Value2 = =Format(Now,"dd/mmmm/yyyy hh:mm:ss:ms") is in the Open Event.
So when closing the workbook it should display a message box showing the used time in working with the workbook.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Paste the following in the ThisWorkbook module :

VBA Code:
Option Explicit

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    VBA_Calculate_Minutes_Between_Two_Times
End Sub
 
Upvote 0
Please when I run the code it gives me a run-time error '424' saying "Object required" any help
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,869
Members
449,054
Latest member
juliecooper255

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