In this article, we will demonstrate you 2 smart ways to quickly get all the tasks of the day in your Word via VBA.
If you are the guy who prefer to make detailed schedule for work, then you will need the following tips to quickly get tasks of the day. In our times, we see information explosion everywhere. Similarly, we don’t think you need to open your memo and look through all tasks there. Instead, wouldn’t it be better to get just specific tasks that day?
To achieve so, you ought to do the following things one by one.
Arrange All Tasks in an Excel File
Before all, you need to create an Excel file to store all tasks there.
- First, open Excel and open a new worksheet.
- Then enter dates in the cells of the first column.
- Next enter detailed tasks in the second column.
- Rename the worksheet as “Tasks”.
- Save and name the Excel file as “TaskFile”.
The file should be put in the following folder:
Click here to download an example file.
Method 1: Get Tasks of the Day
- First and foremost, press “Alt+ F11” to open VBA editor in Word.
- Next create a new module by clicking “Normal”.
- Then click “Insert” and choose “Module”.
- Double click on module to open it.
- And paste the following codes:
Sub SeeTasksForTodayOrTomorrow() Dim objExcel As Excel.Application Dim objWorkbook As Excel.Workbook Dim objWorksheet As Excel.Worksheet Dim dtDate As Date, dtNextDate As Date Dim strdtDate As String, strRowNumber As String, strdtNextDate As String, strRowNumberTomorrow As String Dim objFoundCellToday As Object, objFoundCellTomorrow As Object Dim objDoc As Document Dim strButtonValue As String Set objDoc = ActiveDocument dtDate = Date dtNextDate = Date + 1 strdtDate = Int(dtDate) strdtNextDate = Int(dtNextDate) Set objExcel = CreateObject("Excel.Application") Set objWorkbook = objExcel.Workbooks.Open("C:\Users\Public\Documents\Sample\TaskFile.xlsx") Set objWorksheet = objWorkbook.Sheets("Tasks") objExcel.Visible = False Set objFoundCellToday = objWorksheet.Cells.Find(What:=strdtDate) If objFoundCellToday Is Nothing Then MsgBox ("No task today!") Else strRowNumber = objFoundCellToday.Row strButtonValue = MsgBox("Tasks for " & strdtDate & ":" & vbNewLine & objWorksheet.Cells(strRowNumber, 2).Value & vbNewLine & vbNewLine & "Do you want to see tasks for tomorrow?", vbYesNo) If strButtonValue = vbNo Then Exit Sub Else Set objFoundCellTomorrow = objWorksheet.Cells.Find(What:=strdtNextDate) If objFoundCellTomorrow Is Nothing Then MsgBox ("No task for " & strdtNextDate & " !") Else strRowNumberTomorrow = objFoundCellTomorrow.Row MsgBox ("Tasks for " & strdtNextDate & ":" & vbNewLine & objWorksheet.Cells(strRowNumberTomorrow, 2).Value) End If End If End If End Sub
- Next alter the codes. Find code line “Set objWorkbook = objExcel.Workbooks.Open(“C:\Users\Public\Documents\Sample\TaskFile.xlsx”)”. Then replace the file path with that of your Excel file.
- Save the codes.
- Then go to assign a button for the macro. As for how to do it, you can refer to this article: How to Remove the Formatting of Pasted Texts with Macro and VBA in Your Word
- Run the macro by clicking button. There will be a message box, showing you the tasks you need to fulfill today. By the way, you can choose to see tomorrow’s tasks as well by clicking “Yes” on the box.
Method 2: Get Tasks of a Specific Day
Now there is another feature for you to enter a date and get all tasks of that day.
- Firstly, install and run a macro using above steps in method 1.
- Replace that macro with this one:
Sub SearchTasksForASpecificDay() Dim objExcel As Excel.Application Dim objWorkbook As Excel.Workbook Dim objWorksheet As Excel.Worksheet Dim strDate As String Dim objFoundCell As Object Set objExcel = CreateObject("Excel.Application") Set objWorkbook = objExcel.Workbooks.Open("C:\Users\Public\Documents\Sample\TaskFile.xlsx") Set objWorksheet = objWorkbook.Sheets("Tasks") objExcel.Visible = False strDate = InputBox("Enter a Date ", "Find date", Default:=Format(Date, "Short Date")) strDate = Format(strDate, "Short Date") Set objFoundCell = objWorksheet.Cells.Find(What:=CDate(strDate)) If objFoundCell Is Nothing Then MsgBox ("No task for " & strDate & " !") Else strRowNumber = objFoundCell.Row MsgBox ("Tasks for " & strDate & ":" & vbNewLine & objWorksheet.Cells(strRowNumber, 2).Value) End If End Sub
- Similarly, replace the path in the macro with an actual one.
- Running the macro. First, enter a specific date in the text box of the input box popped up.
- And click “OK” to proceed.
- Finally, there will be a message box, returning the searching result.
When Documents Go Wrong
It’s inevitable to run into some errors while using Word. Therefore, it’s necessary to learn to deal with various situations possibly occur. The first thing you do to fix docx should be using the built-in repair tool in Word. Next, if the problem remains, then it’s high time you started getting a specialized repairing tool.
Vera Chen is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including corrupted xls and pdf repair software products. For more information visit www.datanumen.com