datepowerpointpowerpoint-2016

PowerPoint: Add Date of Yesterday and Tomorrow to a Slide


I want to have a table on my PowerPoint (2016) slide which should look like this:

sysdate - 1 sysdate sysdate + 1
02.09.2021 03.09.2021 04.09.2021

To keep the slides intuitive, the dates should be updated automatically.

By using Insert -> Text -> Date & Time I can add a field containing the current date for the center column.

How do I add a dynamic field for yesterday and tomorrow?


Solution

  • First, follow the steps here to name your table. After that, insert a module (Alt+F11, Insert - Module) and add this piece of code:

    Sub SetTableHeaders()
        
        Const SlideNo = 1
        Const TableName = "TableName Here"
        
        Dim MyTable As Table
        Set MyTable = ActivePresentation.Slides(SlideNo).Shapes(TableName).Table
        
        MyTable.Rows(1).Cells(1).Shape.TextFrame.TextRange.Text = Format(Now - 1, "yyyy-mm-dd")
        MyTable.Rows(1).Cells(2).Shape.TextFrame.TextRange.Text = Format(Now, "yyyy-mm-dd")
        MyTable.Rows(1).Cells(3).Shape.TextFrame.TextRange.Text = Format(Now + 1, "yyyy-mm-dd")
        
    End Sub
    

    Replace the SlideNo and TableName values with the right ones. Run it (F5) to set the headers.