简体   繁体   English

使用 excel VBA 在 powerpoint 中更改页眉/页脚日期和时间的格式

[英]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.一切正常,除了.DateAndTime.Format 没有更改幻灯片左下角的日期格式。 The date is visible as 4/10/2020, but I can't get it to change to April 10, 2020 using the below:日期显示为 2020 年 4 月 10 日,但我无法使用以下命令将其更改为 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

I think you found a bug, because VBA won't change the date format on a master or its child layouts.我认为您发现了一个错误,因为 VBA 不会更改主布局或其子布局上的日期格式。 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.但是,当您插入新幻灯片时,日期仍将反映布局上设置的格式,您必须重新运行宏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM