vbapowerpointdatetime-formatheaderfooter

Using excel VBA to change format of headers/footers date and time in powerpoint


I currently have the following set up. Everything is working fine, except .DateAndTime.Format is not changing the date format in the bottom left hand corner of the slide. The date is visible as 4/10/2020, but I can't get it to change to April 10, 2020 using the below:

  Set PowerPointApp = GetObject(class:="PowerPoint.Application")
  Set myPresentation = PowerPointApp.Presentations.Add
    myPresentation.ApplyTemplate "[template file here]"
  Const ppSlideSizeA4Paper = 2
    myPresentation.PageSetup.SlideSize = ppSlideSizeA4Paper
  With myPresentation.SlideMaster.HeadersFooters

    .SlideNumber.Visible = True
    .DateAndTime.Visible = True
    .DateAndTime.UseFormat = True
    .DateAndTime.Format = ppDateTimeMMMMdyyyy

  End With

Solution

  • I think you found a bug, because VBA won't change the date format on a master or its child layouts. It's possible to set on the slides:

    Sub DateTime()
        Dim oSlide As Slide
        For Each oSlide In ActivePresentation.Slides
            With oSlide.HeadersFooters
                .SlideNumber.Visible = True
                With .DateAndTime
                    .Format = ppDateTimeMMMMdyyyy
                    .Visible = msoTrue
                End With
            End With
        Next oSlide
    End Sub
    

    However, when you insert a new slide, the date will still reflect the format set on the layout and you'll have to rerun the macro.