ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   code to caputre time in vb in a specific cell (https://www.excelbanter.com/excel-programming/416082-code-caputre-time-vbulletin-specific-cell.html)

jts

code to caputre time in vb in a specific cell
 
I am starting to use macros in Excel and need help trying to find the visual
basic code (also new at vb) to capure time. I need to start time and finish
time when wroking in Excel to time I sepend completing one form.
JTS

RyanH

code to caputre time in vb in a specific cell
 
You will need some sort of event to capture the start time and ending time.
I chose the Workbook Open event to capture the start time and BeforeSave
event to capture the ending time. Place this code below in the ThisWorkbook
Module. When you save the workbook a message box will appear telling you the
time it took to fill the form out.

Option Explicit

Dim StartTime As Date
Dim EndTime As Date

Private Sub Workbook_Open()

StartTime = Format(Now, "hh:mm:ss")

End Sub

Private Sub Workbook_BeforeSave()

EndTime = Format(Now, "hh:mm:ss")
MsgBox "Time Elasped = " & Format(EndTime - StartTime, "hh:mm:ss")

End Sub

Hope this helps! If so please click Yes below.
--
Cheers,
Ryan


"JTS" wrote:

I am starting to use macros in Excel and need help trying to find the visual
basic code (also new at vb) to capure time. I need to start time and finish
time when wroking in Excel to time I sepend completing one form.
JTS



All times are GMT +1. The time now is 11:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com