Making a mini-calendar in vba with userform

I’m working on a mini-calendar that is poping up when I click on a date in excel. The mini-calendar is made of userform. When I click on a date in the calendar, it transcribes it in the cell. Everything works fine. However, I would like to be able to click on the little arrows in the calendar to change the months and the years.

I have already this code written in the worksheet :

And this code in the userform coding window :

I already tried this code but in vain :

Private Sub MonthUp_Click()
’ Diminuer le mois de 1
Dim currentDate As Date
currentDate = DateSerial(UserForm1.Controls(« Année »).Caption, MonthNameToNumber(UserForm1.Controls(« Mois »).Caption), 1)
currentDate = DateAdd(« m », -1, currentDate)
UserForm1.Controls(« Mois »).Caption = VBA.monthName(Month(currentDate), True)
UserForm1.Controls(« Année »).Caption = Year(currentDate)
Feuil4.buildCalendar
End Sub

Private Sub MonthDown_Click()
’ Augmenter le mois de 1
Dim currentDate As Date
currentDate = DateSerial(UserForm1.Controls(« Année »).Caption, MonthNameToNumber(UserForm1.Controls(« Mois »).Caption), 1)
currentDate = DateAdd(« m », 1, currentDate)
UserForm1.Controls(« Mois »).Caption = VBA.monthName(Month(currentDate), True)
UserForm1.Controls(« Année »).Caption = Year(currentDate)
Feuil4.buildCalendar
End Sub

Private Sub YearUp_Click()
’ Diminuer l’année de 1
UserForm1.Controls(« Année »).Caption = UserForm1.Controls(« Année »).Caption - 1
Feuil4.buildCalendar
End Sub

Private Sub YearDown_Click()
’ Augmenter l’année de 1
UserForm1.Controls(« Année »).Caption = UserForm1.Controls(« Année »).Caption + 1
Feuil4.buildCalendar
End Sub

Function MonthNameToNumber(monthName As String) As Integer
’ Convertir le nom du mois en numéro de mois
Dim i As Integer
For i = 1 To 12
If VBA.monthName(i, False) = monthName Then
MonthNameToNumber = i
Exit Function
End If
Next i
End Function

2

Finally, it works with this code in the userform coding area:

Private Sub IblDown_Click()
Dim strd As String
Dim iMonth, iYear, iStartofMonthDay As Integer
Dim startOfMonth, trackingDate As Date
Dim cDay As control

strd = Mois.Caption
Mois.Caption = Format(DateAdd("m", -1, CDate(strd)), "mmmm yyyy")

iYear = Year(DateAdd("m", -1, CDate(strd)))
iMonth = Month(DateAdd("m", -1, CDate(strd)))

startOfMonth = DateSerial(iYear, iMonth, 1)
iStartofMonthDay = Weekday(startOfMonth, vbMonday)

trackingDate = DateAdd("d", -iStartofMonthDay + 1, startOfMonth)
For i = 1 To 30
    ' Skip weekends
    While Weekday(trackingDate) = 7 Or Weekday(trackingDate) = 1 ' If it's Saturday or Sunday
        trackingDate = DateAdd("d", 1, trackingDate) ' Skip to next day
    Wend

    Set cDay = MiniCalendrier.Controls("Jour" & i)
    cDay.Caption = Day(trackingDate)
    cDay.Tag = trackingDate
    
    ' Check if the month of the trackingDate is different from the current month
    If Month(trackingDate) <> iMonth Then
        cDay.ForeColor = 8421504 ' Change the color to gray
    Else
        cDay.ForeColor = 0 ' Change the color to black
    End If

    trackingDate = DateAdd("d", 1, trackingDate)
Next
End Sub

Private Sub IblUp_Click()
Dim strd As String
Dim iMonth, iYear, iStartofMonthDay As Integer
Dim startOfMonth, trackingDate As Date
Dim cDay As control

strd = Mois.Caption
Mois.Caption = Format(DateAdd("m", 1, CDate(strd)), "mmmm yyyy")

iYear = Year(DateAdd("m", 1, CDate(strd)))
iMonth = Month(DateAdd("m", 1, CDate(strd)))

startOfMonth = DateSerial(iYear, iMonth, 1)
iStartofMonthDay = Weekday(startOfMonth, vbMonday)

trackingDate = DateAdd("d", -iStartofMonthDay + 1, startOfMonth)
For i = 1 To 30
    ' Skip weekends
    While Weekday(trackingDate) = 7 Or Weekday(trackingDate) = 1 ' If it's Saturday or Sunday
        trackingDate = DateAdd("d", 1, trackingDate) ' Skip to next day
    Wend

    Set cDay = MiniCalendrier.Controls("Jour" & i)
    cDay.Caption = Day(trackingDate)
    cDay.Tag = trackingDate
    
    ' Check if the month of the trackingDate is different from the current month
    If Month(trackingDate) <> iMonth Then
        cDay.ForeColor = 8421504 ' Change the color to gray
    Else
        cDay.ForeColor = 0 ' Change the color to black
    End If

    trackingDate = DateAdd("d", 1, trackingDate)
Next
End Sub

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật