Private Sub Command1_Click()
Dim dt_Pascoa As Variant 'feriado de páscoa
Dim dt_Carnaval As Variant 'feriado de carnaval
Dim dt_SextaSanta As Variant 'feriado de sexta-feira santa
Dim dt_CorpusC As Variant 'feriado corpus cristi
Dim Data As Variant 'data informada pelo usuário
Dim diautil As Integer 'variavel de controle -> 5 dias úteis
Dim dataaux As Date 'data após x dias úteis (x = diautil)
Data = Format(CDate(Text1.Text), "dd/mm/yyyy")
subFeriadosMoveis Year(Data), dt_Pascoa, dt_Carnaval, dt_SextaSanta, dt_CorpusC
diautil = 0
dataaux = Data
Do While diautil < 5
dataaux = DateAdd("d", 1, dataaux)
If (Weekday(dataaux) <> 1) And (Weekday(dataaux) <> 7) Then'se dia não for sábado ou domingo
If (dataaux <> dt_Pascoa) And (dataaux <> dt_Carnaval) And (dataaux <> dt_SextaSanta) And (dataaux <> dt_CorpusC) Then 'se dia não for feriado
diautil = diautil + 1 'se for dia útil conta o dia
End If
End If
Loop
MsgBox dataaux
End Sub
Private Sub subFeriadosMoveis(ByVal Ano As Long, ByRef dt_Pascoa As Variant, ByRef dt_Carnaval As Variant, ByRef dt_SextaSanta As Variant, ByRef dt_CorpusC As Variant)
'Esta função calcula os feriados móveis nacionais:
'Pascoa, Carnaval, Sexta-Feira Santa e CorpusC.
Dim A, B, C, D, E, F, G, H, I, K, L, M, P, Q As Long
A = (Ano Mod 19)
B = Int(Ano / 100)
C = (Ano Mod 100)
D = Int(B / 4)
E = (B Mod 4)
F = Int((B + 8) / 25)
G = Int((B - F + 1) / 3)
H = ((19 * A + B - D - G + 15) Mod 30)
I = Int(C / 4)
K = (C Mod 4)
L = ((32 + 2 * E + 2 * I - H - K) Mod 7)
M = Int((A + 11 * H + 22 * L) / 451)
P = Int((H + L - 7 * M + 114) / 31)
Q = ((H + L - 7 * M + 114) Mod 31)
dt_Pascoa = CDate((Q + 1) & "/" & P & "/" & Ano)
dt_Carnaval = DateAdd("d", -47, dt_Pascoa)
dt_SextaSanta = DateAdd("d", -2, dt_Pascoa)
dt_CorpusC = DateAdd("d", 60, dt_Pascoa)
End Sub