KutoolsforOffice — 一套方案,五大工具。事半功倍。三月特賣:20% 折扣

如何在 Excel 中輕鬆建立專屬行事曆?

作者技術支援修改日期

Excel 日曆能協助您輕鬆追蹤重要事件,例如某人開始新工作或物品的交付時間,讓關鍵日期一目了然、清晰明確。在本指南中,我將示範如何在 Excel 中製作月曆與年曆:不僅會介紹如何運用範本快速設定,也會逐步說明從零開始建立日曆的方法,滿足追求高度自訂化的使用者需求。無論是工作安排還是個人規劃,都能因此井然有序、掌握先機。

建立行事曆

使用 Excel 日曆範本建立年度日曆

透過 Kutools for Excel 快速建立月曆或年曆

使用 VBA 程式碼建立月曆


使用 Excel 日曆範本建立年度日曆

使用此方法時,請確保電腦已連接網路,才能順利下載行事曆範本

1. 前往檔案頁籤,點選左側窗格中的新增按鈕,再點選行事曆(位於)建議的搜尋)。請參閱螢幕截圖:

點擊「新增」按鈕,然後點擊「行事曆」

2. 選取您喜愛的行事曆範本,並雙擊以建立年度行事曆。

選取其中一個行事曆範本

結果

行事曆已插入


透過 Kutools for Excel 快速建立月曆或年曆

永久日曆工具可讓您在 Kutools for Excel 中快速建立自訂的月份或年度行事曆,每個月的行事曆都會自動置於獨立的工作表中!

Kutools for Excel 提供超過 300 項進階功能,簡化複雜作業,提升創意與效率。整合 AI 功能,Kutools 能精準自動化任務,讓資料管理輕鬆無負擔。Kutools for Excel 詳細資訊……         免費試用……

安裝 Kutools for Excel 後,請點選 KUTOOLS PLUS 工作表 永久日曆。在彈出的永久日曆對話方塊中,請依下列步驟操作:

  • 若要建立月曆,請先透過下拉清單指定欲建立日曆的月份,再點選建立

指定月份以建立月曆

  • 若要建立年曆,請透過下拉選單指定欲建立日曆的年份範圍,然後點擊建立

指定年份以建立年曆

結果
  • 月曆:

已插入月曆

  • 年曆:

已插入年曆

提示:若要使用此功能,您需先安裝 Kutools for Excel,請 立即點擊下載並享有 30 天免費試用

使用 VBA 程式碼建立月曆

透過以下 VBA 程式碼,您能快速建立月曆。操作步驟如下:

1. 按下 Alt+F11 鍵,即可開啟 Microsoft Visual Basic for Applications 視窗!

2. 將出現一個新視窗,請點選插入> 模組,並在模組中輸入下列程式碼:

 Sub CalendarMaker()
ActiveSheet.Protect DrawingObjects:=False, Contents:=False, _
Scenarios:=False
Application.ScreenUpdating = False
On Error GoTo MyErrorTrap
Range("a1:g14").Clear
MyInput = InputBox("Type in Month and year for Calendar ")
If MyInput = "" Then Exit Sub
StartDay = DateValue(MyInput)
If Day(StartDay) <> 1 Then
StartDay = DateValue(Month(StartDay) & "/1/" & _
Year(StartDay))
End If
Range("a1").NumberFormat = "mmmm yyyy"
With Range("a1:g1")
.HorizontalAlignment = xlCenterAcrossSelection
.VerticalAlignment = xlCenter
.Font.Size = 18
.Font.Bold = True
.RowHeight = 35
End With
With Range("a2:g2")
.ColumnWidth = 11
.VerticalAlignment = xlCenter
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Orientation = xlHorizontal
.Font.Size = 12
.Font.Bold = True
.RowHeight = 20
End With
Range("a2") = "Sunday"
Range("b2") = "Monday"
Range("c2") = "Tuesday"
Range("d2") = "Wednesday"
Range("e2") = "Thursday"
Range("f2") = "Friday"
Range("g2") = "Saturday"
With Range("a3:g8")
.HorizontalAlignment = xlRight
.VerticalAlignment = xlTop
.Font.Size = 18
.Font.Bold = True
.RowHeight = 21
End With
Range("a1").Value = Application.Text(MyInput, "mmmm yyyy")
DayofWeek = Weekday(StartDay)
CurYear = Year(StartDay)
CurMonth = Month(StartDay)
FinalDay = DateSerial(CurYear, CurMonth + 1, 1)
Select Case DayofWeek
Case 1
Range("a3").Value = 1
Case 2
Range("b3").Value = 1
Case 3
Range("c3").Value = 1
Case 4
Range("d3").Value = 1
Case 5
Range("e3").Value = 1
Case 6
Range("f3").Value = 1
Case 7
Range("g3").Value = 1
End Select
For Each cell In Range("a3:g8")
RowCell = cell.Row
ColCell = cell.Column
If cell.Column = 1 And cell.Row = 3 Then
ElseIf cell.Column <> 1 Then
If cell.Offset(0, -1).Value >= 1 Then
cell.Value = cell.Offset(0, -1).Value + 1
If cell.Value > (FinalDay - StartDay) Then
cell.Value = ""
Exit For
End If
End If
ElseIf cell.Row > 3 And cell.Column = 1 Then
cell.Value = cell.Offset(-1, 6).Value + 1
If cell.Value > (FinalDay - StartDay) Then
cell.Value = ""
Exit For
End If
End If
Next
For x = 0 To 5
Range("A4").Offset(x * 2, 0).EntireRow.Insert
With Range("A4:G4").Offset(x * 2, 0)
.RowHeight = 65
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlTop
.WrapText = True
.Font.Size = 10
.Font.Bold = False
.Locked = False
End With
With Range("A3").Offset(x * 2, 0).Resize(2, _
7).Borders(xlLeft)
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
With Range("A3").Offset(x * 2, 0).Resize(2, _
7).Borders(xlRight)
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
Range("A3").Offset(x * 2, 0).Resize(2, 7).BorderAround _
Weight:=xlThick, ColorIndex:=xlAutomatic
Next
If Range("A13").Value = "" Then Range("A13").Offset(0, 0) _
.Resize(2, 8).EntireRow.Delete
ActiveWindow.DisplayGridlines = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, _
Scenarios:=True
ActiveWindow.WindowState = xlMaximized
ActiveWindow.ScrollRow = 1
Application.ScreenUpdating = True
Exit Sub
MyErrorTrap:
MsgBox "You may not have entered your Month and Year correctly." _
& Chr(13) & "Spell the Month correctly" _
& " (or use 3 letter abbreviation)" _
& Chr(13) & "and 4 digits for the Year"
MyInput = InputBox("Type in Month and year for Calendar")
If MyInput = "" Then Exit Sub
Resume
End Sub 

3. 接著點擊執行按鈕,或按下 F5 鍵來啟動應用程式,隨即會彈出提示方塊,您可在空白欄位中輸入月份與年份。

在文字方塊中輸入月份和年份

結果

已插入月曆