Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
32 views2 pages

Time Log Code

The document contains a VBA code that generates funny messages for employees when they clock in and out. It includes functions to log the time and date of the employee's actions in a worksheet and display a humorous message based on their action. The code features two main subroutines, TimeInOnly and TimeOutOnly, which handle the recording of time and retrieval of funny messages.

Uploaded by

Mohammad Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views2 pages

Time Log Code

The document contains a VBA code that generates funny messages for employees when they clock in and out. It includes functions to log the time and date of the employee's actions in a worksheet and display a humorous message based on their action. The code features two main subroutines, TimeInOnly and TimeOutOnly, which handle the recording of time and retrieval of funny messages.

Uploaded by

Mohammad Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

' Funny message generator

Function GetFunnyMessage(action As String) As String


Dim messagesIn As Variant
Dim messagesOut As Variant
Dim index As Integer

messagesIn = Array( _
"Time In complete! Let's survive the day ???", _
"Back to the grind! ????", _
"Clocked in! The coffee better be ready ??", _
"Welcome back to your second home ????", _
"Here we go again... ?? Good luck!" _
)

messagesOut = Array( _
"Work complete! Go home and chill ????", _
"Bye Felicia! ???????", _
"Logging out like a boss ?????", _
"Time out! Don’t forget your snacks! ????", _
"You're freeeeeee! ?????" _
)

Randomize
index = Int(Rnd() * UBound(messagesIn) + 1)

If action = "in" Then


GetFunnyMessage = messagesIn(index)
Else
GetFunnyMessage = messagesOut(index)
End If
End Function

' Time In
Sub TimeInOnly()
Dim wsRecord As Worksheet
Dim employeeName As String
Dim currentTime As String
Dim currentDate As String
Dim lastRow As Long
Dim msg As String

Set wsRecord = ThisWorkbook.Sheets("Record")


employeeName = InputBox("Enter your name to Time In:", "Time In")
If employeeName = "" Then Exit Sub

currentTime = Format(Now, "hh:mm:ss AM/PM")


currentDate = Format(Now, "dd-mmm-yy")
lastRow = wsRecord.Cells(wsRecord.Rows.Count, "B").End(xlUp).Row + 1

' Record log


wsRecord.Cells(lastRow, "B").Value = employeeName
wsRecord.Cells(lastRow, "C").Value = currentDate
wsRecord.Cells(lastRow, "D").Value = currentTime

' Reflect in active sheet cell C6


ThisWorkbook.ActiveSheet.Range("C6").Value = currentTime

msg = GetFunnyMessage("in")
MsgBox "? " & employeeName & " clocked in at " & currentTime & vbCrLf & msg,
vbInformation, "Time In"
End Sub

' Time Out


Sub TimeOutOnly()
Dim wsRecord As Worksheet
Dim employeeName As String
Dim currentTime As String
Dim lastRow As Long
Dim msg As String

Set wsRecord = ThisWorkbook.Sheets("Record")


employeeName = InputBox("Enter your name to Time Out:", "Time Out")
If employeeName = "" Then Exit Sub

currentTime = Format(Now, "hh:mm:ss AM/PM")


lastRow = wsRecord.Cells(wsRecord.Rows.Count, "B").End(xlUp).Row

Do While wsRecord.Cells(lastRow, "B").Value <> employeeName And lastRow > 1


lastRow = lastRow - 1
Loop

If wsRecord.Cells(lastRow, "B").Value = employeeName Then


wsRecord.Cells(lastRow, "E").Value = currentTime

' Reflect in active sheet cell C7


ThisWorkbook.ActiveSheet.Range("C7").Value = currentTime

msg = GetFunnyMessage("out")
MsgBox "?? " & employeeName & " clocked out at " & currentTime & vbCrLf &
msg, vbInformation, "Time Out"
Else
MsgBox "?? Name not found in Record sheet.", vbExclamation, "Time Out
Error"
End If
End Sub

You might also like