Private Sub Workbook_Open()
Dim r As Range, Holiday As Range, h As Range, DateCel As Range
Dim wb As Workbook
Dim sFileName As String, EmpName As String
Dim ws As Worksheet
Dim d As Date
Set wb = ThisWorkbook
Set r = wb.Sheets(1).Range("C1")
Application.EnableEvents = False
Application.EnableAutoComplete = False
For Each ws In Worksheets
If ws.Name <> "Summary" Then
ws.Protect , UserInterfaceOnly:=True
End If
Next ws
If IsEmpty(r) Then
wb.Sheets(2).Range("B4") = DateSerial(Year(Now()), 1, 1)
Call IsHoliday
With Welcome
.StartUpPosition = 0
.Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
.Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
.Show
End With
EmpName = Welcome.TextBox1.Text
If Welcome.TextBox1.Text = "Exit" Then
Unload Welcome
GoTo ExitMacro
Else
wb.Sheets(2).Range("L28").Value = 1.68 'Set amount of sick hours accrued each pay period
wb.Sheets(2).Range("I21").Value = Welcome.SickHrs.Text
wb.Sheets(2).Range("J21").Value = Welcome.VacHrs.Text
wb.Sheets(1).Range("C1").Value = EmpName 'Insert name that was entered into the Welcom Form
If Welcome.CheckBox1.Value = True Then
StartDate = MsgBox(Prompt:="Will you reach 7 year seniority with Century this year?", _
Buttons:=vbYesNo, Title:="")
If StartDate = vbNo Then
Else
StartDateInput = InputBox("Please enter the date you will reach seniority 'dd/mm/yyyy'")
wb.Sheets(1).Range("C27").Value = StartDateInput
End If
ElseIf Welcome.CheckBox2.Value = True Then
wb.Sheets(2).Range("L29").Value = 5
End If
sFileName = EmpName & " Time Card " & Year(Now()) & ".xlsm"
Application.Dialogs(xlDialogSaveAs).Show Arg1:=sFileName, Arg2:=xlOpenXMLWorkbookMacroEnabled
Unload Welcome
End If
End If ' IsEmpty(r)
Set ws = wb.Sheets(2)
ws.Activate
ws.Range("D4").Select
Set wb = Nothing
Set r = Nothing
Set JanDate = Nothing
Set ws = Nothing
ExitMacro:
Application.EnableEvents = True
End Sub
Module that calculates Holidays
Sub IsHoliday()
Dim r As Range
Dim wb As Workbook
Dim sFileName As String
Dim pass As String
Dim ws As Worksheet
Dim DateCels As Range
Dim DateCel As Range
Dim d As Date
Dim h As Range
Dim Holiday As Range
Dim IsHol As Boolean
Dim EmpName As String
For Each ws In Worksheets
If ws.Name <> "Summary" Then
Set DateCels = ws.Range("B4:B18,B35:B50")
Set Holiday = ws.Range("M4:M18,M35:M50")
Holiday.ClearContents
For Each DateCel In DateCels
If DateCel = "" Then
Else
Set h = DateCel.Offset(, 11)
d = DateCel.Value
Select Case d
'1. New Year's Day
Case DateSerial(Year(d), 1, 1)
If Weekday(d) = 1 Then 'New Year's Day is on Sunday, New Years Eve is on Saturday
h.Offset(1, 0).Value = 8
ElseIf Weekday(d) = 7 Then 'New Years Day is on Saturday, New Year's Eve of year before is on Friday
ElseIf Weekday(d) = 2 Then 'This means New Year's Day of the year before is on a Sunday
Else
h.Value = 8
End If
'2. Memorial Day -- Last Monday in May
Case DateSerial(Year(d), 5, Choose(Weekday(DateSerial(Year(d), 5, 1)), 30, 29, 28, 27, 26, 25, 31))
h.Value = 8
'3. Independence Day
Case DateSerial(Year(d), 7, 4)
If Weekday(d) = 1 Then
h.Offset(1, 0).Value = 8
ElseIf Weekday(d) = 7 Then
h.Offset(-1, 0).Value = 8
Else
h.Value = 8
End If
'4. Labor Day -- First Monday in September
Case DateSerial(Year(d), 9, Choose(Weekday(DateSerial(Year(d), 9, 1)), 2, 1, 7, 6, 5, 4, 3))
h.Value = 8
'5. Thanksgiving Day -- Fourth Thursday in November & Day afte Thanksgiving
Case DateSerial(Year(d), 11, Choose(Weekday(DateSerial(Year(d), 11, 1)), 26, 25, 24, 23, 22, 28, 27))
h.Value = 8
h.Offset(1, 0).Value = 8
'6. Christmas Eve and Christmas Day
Case DateSerial(Year(d), 12, 24)
If Weekday(d) = 1 Then 'Christmas Eve is on a Sunday which means Christmas day is on a Monday
h.Offset(1, 0).Value = 4
h.Offset(2, 0).Value = 8
ElseIf Weekday(d) = 7 Then
h.Offset(-1, 0).Value = 4 'Christmas Eve is on a Saturday which means Christmas Day is on a Sunday
h.Offset(2, 0).Value = 8
Else
h.Value = 4
h.Offset(1, 0).Value = 8
End If
'7. New Year's Eve
Case DateSerial(Year(d), 12, 31)
If Weekday(d) = 1 Then 'New Year's Eve is on a Sunday, New Year's Day is on Monday
ElseIf Weekday(d) = 6 Then 'New Years Eve is on Firday, New Year's Day is on Saturday
h.Offset(-1, 0).Value = 8 'Because New Year's Day's holiday pay gets taken on the Friday
h.Offset(-2, 0).Value = 4 'New Year's Eve's half day gets take on the Thursday
ElseIf Weekday(d) = 7 Then 'New Year's Eve is on Satruday, New Year's Day is on Sunday
h.Offset(-1, 0).Value = 4
Else
h.Value = 4
End If
End Select
End If 'DateCel.Value = ""
Next DateCel
End If
Next ws
End Sub
Hopefully that answers your questions, but it doesn't hurt my feelings if you don't look at it either. Just trying to be helpful.
Bookmarks