1

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?

Thanthla
  • 526
  • 1
  • 8
  • 29

1 Answers1

3

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.

Sam
  • 5,424
  • 1
  • 18
  • 33
  • The code seems to work. But it is not executed automatically. Can I make it run automatically, if "SlideNo" is shown? – Thanthla Sep 03 '21 at 09:18
  • 2
    `Sub OnSlideShowPageChange(ByVal SSW As SlideShowWindow) If SSW.View.CurrentShowPosition = SlideNo Then SetTableHeaders End If End Sub` did the trick – Thanthla Sep 03 '21 at 09:25