簡體   English   中英

使用 excel VBA 在 powerpoint 中更改頁眉/頁腳日期和時間的格式

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

我目前有以下設置。 一切正常,除了.DateAndTime.Format 沒有更改幻燈片左下角的日期格式。 日期顯示為 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

我認為您發現了一個錯誤,因為 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

但是,當您插入新幻燈片時,日期仍將反映布局上設置的格式,您必須重新運行宏。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM