如何在Excel中创建月历/年历?
兑换中心 9430 2026-02-07 17:31:41

如何在Excel中创建月历/年历? Author Sun • Last modified 2025-08-22 有时,您需要在Excel中创建特定月份或年份的日历,如何快速解决这个问题呢?本教程介绍了在Excel中快速创建月历或年历的技巧。

通过Excel模板创建月历或年历

通过VBA创建月历

使用永久日历轻松创建月历或年历

通过Excel模板创建月历或年历在Excel中,您可以使用日历模板来创建月历或年历。

1. 在Excel 2010/2013中,点击 文件 > 新建,在Excel 2007中,点击 Office按钮 > 新建,然后在弹出窗口的右侧部分,在搜索引擎中输入“calendar”。参见截图:

在Excel 2010/2013中

在Excel 2007中

2. 按Enter键,然后多种类型的日历会显示在窗口中。选择您需要的一种日历类型,并在右侧窗格中点击 下载(或创建)。参见截图:

现在,一个新的工作簿中已创建了一个日历。参见截图:

通过VBA创建月历 有时,您需要为指定的月份创建一个月历,例如2015年1月。用上述方法可能很难找到这样的日历模板。这里我介绍一个VBA代码,帮助您创建特定的月历。

太棒了!在 Excel 中像 Chrome、Edge、Firefox 和 Safari 一样使用高效标签页! 每天为您节省 50% 的时间,并减少数千次鼠标点击!

1. 按Alt + F11键打开 Microsoft Visual Basic for Applications窗口,点击 插入 > 模块,然后将以下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. 点击确定。现在,2015年1月的日历已在当前工作表中创建。

但在上述方法中存在一些限制,例如,如果您想一次性创建从1月到5月的日历,则需要使用上述两种方法分别创建五次日历。现在,我介绍一个方便的工具,可以快速轻松地解决这个问题。

使用永久日历轻松创建月历或年历永久日历 是 Kutools for Excel中的强大工具之一,它可以帮助您快速一次性在Excel中创建月历或年历。

1. 点击 Kutools Plus > 工作表 > 永久日历。

2. 在弹出的对话框中,指定要创建日历的月份范围,并点击 创建。参见截图:

然后,一个新的工作簿被创建,其中包含五个日历工作表。参见截图:

提示:

如果您只想创建特定月份的日历,只需在对话框的“从”和“到”文本框中选择相同的月份即可。

点击此处了解更多关于永久日历的信息

最佳Office办公效率工具 🤖 Kutools AI 助手:以智能执行为基础,彻底革新数据分析 |代码生成 |自定义公式创建|数据分析与图表生成 |调用Kutools函数…… 热门功能:查找、选中项的背景色或标记重复项 | 删除空行 | 合并列或单元格且不丢失数据 | 四舍五入…… 高级LOOKUP:多条件VLookup|多值VLookup|多表查找|模糊查找…… 高级下拉列表:快速创建下拉列表 |依赖下拉列表 | 多选下拉列表…… 列管理器: 添加指定数量的列 | 移动列 | 切换隐藏列的可见状态 | 比较区域与列…… 特色功能:网格聚焦 |设计视图 | 增强编辑栏 | 工作簿及工作表管理器 | 资源库(自动文本) | 日期提取 | 合并数据 | 加密/解密单元格 | 按名单发送电子邮件 | 超级筛选 | 特殊筛选(筛选粗体/倾斜/删除线等)…… 15大工具集:12项 文本工具(添加文本、删除特定字符等)|50+种 图表 类型(甘特图等)|40+实用 公式(基于生日计算年龄等)|19项 插入工具(插入二维码、从路径插入图片等)|12项 转换工具(小写金额转大写、汇率转换等)|7项 合并与分割工具(高级合并行、分割单元格等)| …… Kutools支持多种语言——可选择英语、西班牙语、德语、法语、中文等40多种语言!通过Kutools for Excel提升您的Excel技能,体验前所未有的高效办公。 Kutools for Excel提供300多项高级功能,助您提升效率并节省时间。 点击此处获取您最需要的功能……

Kutools for Excel更多详情…… 免费下载…… Office Tab为Office带来多标签界面,让您的工作更加轻松 支持在Word、Excel、PowerPoint中进行多标签编辑与阅读。 在同一个窗口的新标签页中打开和创建多个文档,而不是分多个窗口。 可提升50%的工作效率,每天为您减少数百次鼠标点击! Office Tab更多详情…… 免费下载……所有Kutools加载项,一键安装Kutools for Office套件包含Excel、Word、Outlook和PowerPoint的插件,以及Office Tab Pro,非常适合跨Office应用团队使用。

全能套装——Excel、Word、Outlook和PowerPoint插件+Office Tab Pro 单一安装包、单一授权——数分钟即可完成设置(支持MSI) 协同更高效——提升Office应用间的整体工作效率 30天全功能试用——无需注册,无需信用卡 超高性价比——比单独购买更实惠 Kutools for Office更多详情…… 免费下载……

Copyright © 2022 GXLC网游资讯网-新版本速递_限时活动_礼包兑换 All Rights Reserved.