In today’s article, we will present you 2 quick ways to insert the days or time left before a deadline in your Word document.
Every once in a while, when you are working on an important project, you will find that you have to keep in mind the exact days or time left before the deadline so as to adjust your working pace. Then it shall be a great idea to insert the days or time left before the deadline into your Word document, so they can remind you of the latest time left.
In the following text, we’d like to introduce you 2 methods of how to use macros to calculate and get the value.
Calculate Days Left before the Deadline
- First and foremost, place your cursor at the position where you want to insert the number.
- Then, click “Developer” tab.
- Next click “Visual Basic” in “Code” group to open the VBA editor. Also, you can press “Alt+ F11” instead in case “Developer” tab is not available in your Word.
- Now click “Normal” and then “Insert”.
- Next, choose “Module”.
- Double click the new module to open the editing area on the right side.
- Then paste the following codes there:
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
- Next, click “Run” button.
- You will be greeted with a dialog box, such as below:
Enter the deadline date into the text box and click “OK”.
For easy use in the future, you can click “Macros” under “Developer” tab and choose the right macro then click “Run”. It shall trigger the dialog box.
Calculate Time Left before the Deadline
Sometimes, apart from getting days left, you may also need to know how much time you have left before a specific time. Then, the bellowing macro is what you will need.
- Repeat the first 8 steps above. Only you have to replace the codes with the following:
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
- Remember to hit the “Run” button.
- This time, you will have the “Deadline Time” dialog box. Enter the deadline time then click “OK”.
Keep Files Unharmed
To keep file integrity and store them away from corruption, the best and easiest way is to make backups often. However, we understand it’s hard to stick to a routine, which is why there are so many broken files every day. To repair these problematic files, you will need a corrupted Word repair tool.
Author Introduction:
Vera Chen is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including xlsx error repair tool and pdf repair software products. For more information visit www.datanumen.com