如何在Excel中創建每月/每年的日歷?
在某些時候,您需要在Excel中創建特定的月或年日歷,如何快速解決呢? 本教程介紹了在Excel中快速創建每月或每年日歷的技巧。
通過Excel模板創建每月或每年的日歷
通過VBA創建月歷
通過萬年歷輕松創建月度或年度日歷
通過Excel模板創建每月或每年的日歷
驚人的! 在 Excel 中使用高效的選項卡,如 Chrome、Firefox 和 Safari!
每天節省50%的時間,并減少數千次鼠標單擊!
在Excel中,您可以使用日歷模板來創建每月或每年的日歷。
1.在Excel 2010/2013中,單擊 文件 > 全新,在Excel 2007中,單擊 辦公按鈕 > 全新,然后在彈出窗口的右側部分中輸入 日歷 進入搜索引擎。 看截圖:
在Excel 2010/2013中
在Excel 2007中
2。 按 輸入,然后窗口中會列出多種類型的日歷。 選擇所需的一種日歷,然后單擊 下載(或創建) 在右窗格中。 看截圖:
現在,在新工作簿中創建了一個日歷。 看截圖:
通過VBA創建月歷
有時,您需要為指定的月份創建一個月的日歷,例如2015年XNUMX月。使用上述方法很難找到這樣的日歷模板。 在這里,我介紹了VBA代碼,以幫助您創建特定的每月日歷。

1。 按 Alt + F11鍵 打開鑰匙 Microsoft Visual Basic應用程序 窗口中,單擊 插頁 > 模塊,然后將以下VBA代碼復制并粘貼到窗口中。
VBA:創建每月日歷。
Sub CalendarMaker()
Unprotect sheet if had previous calendar to prevent error.
ActiveSheet.Protect DrawingObjects:=False, Contents:=False, _
Scenarios:=False
Prevent screen flashing while drawing calendar.
Application.ScreenUpdating = False
Set up error trapping.
On Error GoTo MyErrorTrap
Clear area a1:g14 including any previous calendar.
Range("a1:g14").Clear
Use InputBox to get desired month and year and set variable
MyInput.
MyInput = InputBox("Type in Month and year for Calendar ")
Allow user to end macro with Cancel in InputBox.
If MyInput = "" Then Exit Sub
Get the date value of the beginning of inputted month.
StartDay = DateValue(MyInput)
Check if valid date but not the first of the month
-- if so, reset StartDay to first day of month.
If Day(StartDay) <> 1 Then
StartDay = DateValue(Month(StartDay) & "/1/" & _
Year(StartDay))
End If
Prepare cell for Month and Year as fully spelled out.
Range("a1").NumberFormat = "mmmm yyyy"
Center the Month and Year label across a1:g1 with appropriate
size, height and bolding.
With Range("a1:g1")
.HorizontalAlignment = xlCenterAcrossSelection
.VerticalAlignment = xlCenter
.Font.Size = 18
.Font.Bold = True
.RowHeight = 35
End With
Prepare a2:g2 for day of week labels with centering, size,
height and bolding.
With Range("a2:g2")
.ColumnWidth = 11
.VerticalAlignment = xlCenter
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Orientation = xlHorizontal
.Font.Size = 12
.Font.Bold = True
.RowHeight = 20
End With
Put days of week in a2:g2.
Range("a2") = "Sunday"
Range("b2") = "Monday"
Range("c2") = "Tuesday"
Range("d2") = "Wednesday"
Range("e2") = "Thursday"
Range("f2") = "Friday"
Range("g2") = "Saturday"
Prepare a3:g7 for dates with left/top alignment, size, height
and bolding.
With Range("a3:g8")
.HorizontalAlignment = xlRight
.VerticalAlignment = xlTop
.Font.Size = 18
.Font.Bold = True
.RowHeight = 21
End With
Put inputted month and year fully spelling out into "a1".
Range("a1").Value = Application.Text(MyInput, "mmmm yyyy")
Set variable and get which day of the week the month starts.
DayofWeek = WeekDay(StartDay)
Set variables to identify the year and month as separate
variables.
CurYear = Year(StartDay)
CurMonth = Month(StartDay)
Set variable and calculate the first day of the next month.
FinalDay = DateSerial(CurYear, CurMonth + 1, 1)
Place a "1" in cell position of the first day of the chosen
month based on DayofWeek.
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
Loop through range a3:g8 incrementing each cell after the "1"
cell.
For Each cell In Range("a3:g8")
RowCell = cell.Row
ColCell = cell.Column
Do if "1" is in first column.
If cell.Column = 1 And cell.Row = 3 Then
Do if current cell is not in 1st column.
ElseIf cell.Column <> 1 Then
If cell.Offset(0, -1).Value >= 1 Then
cell.Value = cell.Offset(0, -1).Value + 1
Stop when the last day of the month has been
entered.
If cell.Value > (FinalDay - StartDay) Then
cell.Value = ""
Exit loop when calendar has correct number of
days shown.
Exit For
End If
End If
Do only if current cell is not in Row 3 and is in Column 1.
ElseIf cell.Row > 3 And cell.Column = 1 Then
cell.Value = cell.Offset(-1, 6).Value + 1
Stop when the last day of the month has been entered.
If cell.Value > (FinalDay - StartDay) Then
cell.Value = ""
Exit loop when calendar has correct number of days
shown.
Exit For
End If
End If
Next
Create Entry cells, format them centered, wrap text, and border
around days.
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
Unlock these cells to be able to enter text later after
sheet is protected.
.Locked = False
End With
Put border around the block of dates.
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
Turn off gridlines.
ActiveWindow.DisplayGridlines = False
Protect sheet to prevent overwriting the dates.
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, _
Scenarios:=True
Resize window to show all of calendar (may have to be adjusted
for video configuration).
ActiveWindow.WindowState = xlMaximized
ActiveWindow.ScrollRow = 1
Allow screen to redraw with calendar showing.
Application.ScreenUpdating = True
Prevent going to error trap unless error found by exiting Sub
here.
Exit Sub
Error causes msgbox to indicate the problem, provides new input box,
and resumes at the line that caused the error.
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
VBA來自此網站 https://support.microsoft.com/en-us/kb/150774
2。 按 F5 鍵或 運行 按鈕,并彈出一個對話框,提醒您鍵入創建日歷所需的特定月份,請參見屏幕截圖:
3。 點擊 OK。 現在,將在活動工作表中創建一個2015年XNUMX月的日歷。
但是在上述方法中,存在一些局限性,例如,如果要一次創建從一月到五月的日歷,則需要使用上述兩種方法五次創建日歷。 現在,我介紹一個方便的實用程序來快速輕松地解決它
通過萬年歷輕松創建月度或年度日歷
Perpetual Calendar 是的強大工具之一 Kutools for Excel,它可以幫助您一次在Excel中快速創建每月或每年的日歷。
Kutools for Excel, 與超過 300 方便的功能,使您的工作更加輕松。
1。 點擊 企業 > 工作表 > Perpetual Calendar。 看截圖:
2.在彈出的對話框中,指定要創建日歷的月份持續時間,然后單擊 創建。 看截圖:
然后使用五個日歷工作表創建一個新的工作簿。 看截圖:
提示:
如果只想創建特定的月份日歷,則只需在對話框的“從”和“到”文本框中選擇相同的月份。
單擊此處以了解更多關于萬年歷的信息
最佳辦公生產力工具
將小時轉化為分鐘 Kutools for Excel!
準備好增強您的 Excel 任務了嗎? 利用的力量 Kutools for Excel - 您終極的節省時間的工具。 簡化復雜的任務并像專業人士一樣瀏覽數據。 以閃電般的速度體驗 Excel!
為什么需要 Kutools for Excel
??? 超過 300 項強大功能: Kutools 包含 300 多項高級功能,可簡化您在 1500 多種場景中的工作。
?? 卓越的數據處理能力:合并單元格、刪除重復項并執行高級數據轉換 - 所有這些都不費吹灰之力!
?? 高效的批量操作:當你可以聰明地工作時,為什么還要付出額外的努力呢? 輕松批量導入、導出、組合和調整數據。
?? 可定制的圖表和報告:訪問各種附加圖表并生成富有洞察力的報告。
??? 強大的導航窗格:通過強大的列管理器、工作表管理器和自定義收藏夾獲得優勢。
?? 七種類型的下拉列表:通過各種功能和類型的下拉列表使數據輸入變得輕而易舉。
?? 用戶友好:對于初學者來說輕而易舉,對于專家來說是一個強大的工具。
立即下載,與 Excel 一起穿越時空!
閱讀更多
免費下載... 采購...
Office Tab 為 Office 帶來選項卡式界面,讓您的工作更輕松
在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,發布者,Access,Visio和Project。
在同一窗口的新選項卡中而不是在新窗口中打開并創建多個
文檔。
每天將您的工作效率提高50%,并減少數百次鼠標單擊!