在今天的文章中,我们将向您介绍两种在 Word 文档中插入截止日期前剩余天数或时间的快速方法。
每隔一段时间,当你在处理一个重要的项目时,你会发现你必须牢记截止日期前的确切日期或时间,以便调整你的工作节奏。 那么将截止日期前剩余的天数或时间插入到您的 Word 文档中将是一个好主意,这样它们可以提醒您最晚的剩余时间。
在下文中,我们将向您介绍两种使用宏来计算和获取值的方法。
计算截止日期前剩余的天数
- 首先,将光标放在你想插入数字的位置。
- 然后,单击“开发人员”选项卡。
- 接下来单击“代码”组中的“Visual Basic”以打开 VBA 编辑器。 此外,如果您的 Word 中没有“开发人员”选项卡,您可以按“Alt+F11”代替。

- 现在单击“正常”,然后单击“插入”。
- 接下来,选择“模块”。
- 双击新建的模块,打开右侧的编辑区。
- 然后将以下代码粘贴到那里:
Sub CountDownfromTodayToDeadlineDate()
Dim dtDeadlineDate As Date
Dim lDaysLeft As Long
' Input the deadline date to calculate the date difference.
dtDeadlineDate = InputBox("Enter the deadline date", "Deadline Date", "For example:2017/2/14")
lDaysLeft = DateDiff("d", Now, dtDeadlineDate)
' Output the date difference from today to the deadline date in word document.
Selection.Text = "There are " & lDaysLeft & " days left from today to " & dtDeadlineDate & vbCrLf
End Sub
- 接下来,单击“运行”按钮。
- 您将看到一个对话框,如下所示:
在文本框中输入截止日期,然后单击“确定”。
为了以后使用方便,您可以点击“开发者”选项卡下的“宏”,选择合适的宏,然后点击“运行”。 它应触发对话框。
计算截止日期前剩余的时间
有时,除了计算剩余天数外,您可能还需要知道在特定时间之前还剩多少时间。 然后,下面的宏就是您所需要的。
- 重复上面的前 8 个步骤。 只需将代码替换为以下内容:
Sub CountDownfromNowToDeadlineTime()
Dim dtTimeNow As Date
Dim dtDeadlineTime As Date
Dim lTimeLeft As Long
Dim lHour As Long
Dim lMinute As Long
Dim lSecond As Long
' Get the time now and the deadline time.
dtTimeNow = TimeValue(Now)
dtDeadlineTime = InputBox("Enter the deadline time","Deadline Time", "For example:18:00:00")
' Calculate the time difference.
lTimeLeft = DateDiff("s", dtTimeNow, dtDeadlineTime)
lHour = lTimeLeft \ 3600
lTimeLeft = lTimeLeft - lHour * 3600
lMinute = lTimeLeft \ 60
lSecond = lTimeLeft - lMinute * 60
Selection.Text = "There are " & lHour & " hours " & lMinute & " minutes " & lSecond & " seconds left from now to " & dtDeadlineTime & vbCrLf
End Sub
- 记得点击“运行”按钮。
- 这一次,您将看到“截止时间”对话框。 输入截止时间,然后单击“确定”。
保持文件不受伤害
为了保持文件的完整性并使它们远离损坏,最好和最简单的方法是经常进行备份。 但是,我们知道很难坚持常规,这就是为什么每天都有那么多损坏的文件。 要修复这些有问题的文件,您需要 损坏的Word修复工具.
作者简介:
Vera Chen 是一位数据恢复专家 DataNumen, Inc.,它是数据恢复技术领域的世界领先者,包括 xlsx错误修复工具 和 pdf 修复软件产品。 欲了解更多信息,请访问 datanumen.com







