2 Smart Ways to Get Tasks of the Day in Your Word via VBA

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?Get Tasks of the Day in Word

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.

  1. First, open Excel and open a new worksheet.
  2. Then enter dates in the cells of the first column.
  3. Next enter detailed tasks in the second column.
  4. Rename the worksheet as “Tasks”.
  5. Save and name the Excel file as “TaskFile”.Create an Excel File to Store Tasks

 

 

The file should be put in the following folder:

 

C:\Users\Public\Documents\Sample

 

Click here to download an example file.

Method 1: Get Tasks of the Day

  1. First and foremost, press “Alt+ F11” to open VBA editor in Word.
  2. Next create a new module by clicking “Normal”.
  3. Then click “Insert” and choose “Module”.Click "Normal"->Click "Insert"->Click "Module"
  4. Double click on module to open it.
  5. 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
  1. 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.
  2. Save the codes.
  3. 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
  4. 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.Click "Yes" or "No"

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.

  1. Firstly, install and run a macro using above steps in method 1.
  2. 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
  1. Similarly, replace the path in the macro with an actual one.
  2. Running the macro. First, enter a specific date in the text box of the input box popped up.
  3. And click “OK” to proceed.Input a Date->Click "OK"
  4. Finally, there will be a message box, returning the searching result.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.

Author Introduction:

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

Comments are closed.