如何在Excel中创建每月/每年的日历?

网友投稿 277 2023-12-23

如何在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
Copy

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 方便的功能,使您的工作更加轻松。 
免费下载功能齐全60天免费试用

1。 点击 企业 > 工作表 > Perpetual Calendar。 看截图:

2.在弹出的对话框中,指定要创建日历的月份持续时间,然后单击 创建。 看截图:

然后使用五个日历工作表创建一个新的工作簿。 看截图:

提示:

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

单击此处以了解更多关于万年历的信息

最佳办公生产力工具

将小时转化为分钟 Kutools for Excel!

准备好增强您的 Excel 任务了吗? 利用的力量 Kutools for Excel - 您终极的节省时间的工具。 简化复杂的任务并像专业人士一样浏览数据。 以闪电般的速度体验 Excel!

如何在Excel中创建每月/每年的日历?

为什么需要 Kutools for Excel

🛠️  超过 300 项强大功能: Kutools 包含 300 多项高级功能,可简化您在 1500 多种场景中的工作。

📈  卓越的数据处理能力:合并单元格、删除重复项并执行高级数据转换 - 所有这些都不费吹灰之力!

⏱️  高效的批量操作:当你可以聪明地工作时,为什么还要付出额外的努力呢? 轻松批量导入、导出、组合和调整数据。

📊  可定制的图表和报告:访问各种附加图表并生成富有洞察力的报告。

🗄️  强大的导航窗格:通过强大的列管理器、工作表管理器和自定义收藏夹获得优势。

📝  七种类型的下拉列表:通过各种功能和类型的下拉列表使数据输入变得轻而易举。

🎓  用户友好:对于初学者来说轻而易举,对于专家来说是一个强大的工具。

立即下载,与 Excel 一起穿越时空!

阅读更多 免费下载... 采购... 
Office Tab 为 Office 带来选项卡式界面,让您的工作更轻松
在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。 每天将您的工作效率提高50%,并减少数百次鼠标单击!
阅读更多 免费下载... 采购... 

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:如何创建Excel模板的贷款摊销利息计算器?
下一篇:如何在Excel中通过选择创建多个名称?
相关文章