使用 excel VBA 更改 powerpoint 中 headers/footers 日期和时间的格式

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

我目前有以下设置。一切正常,除了 .DateAndTime.Format 没有更改幻灯片左下角的日期格式。日期显示为 4/10/2020,但我无法使用以下方法将其更改为 2020 年 4 月 10 日:

  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

我认为您发现了一个错误,因为 VBA 不会更改主布局或其子布局上的日期格式。可以在幻灯片上设置:

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

但是,当您插入新幻灯片时,日期仍会反映布局上设置的格式,您将不得不重新运行宏。