[英]How to automatically enable Slide number footers in Powerpoint using VBA code?
我已經有一個從 Excel 創建 Powerpoint 演示文稿的宏,但我無法在代碼中啟用幻燈片編號頁腳選項。
具體來說,我想要等效的 VBA 代碼,用於通過在 Powerpoint 中執行以下操作來插入幻燈片編號。 從主頁功能區,Go 到插入選項卡 > 單擊 Header & 頁腳 > 勾選幻燈片編號復選框。 然后,這將自動為所有幻燈片添加頁碼,因此如果用戶更改任何內容(如添加/刪除/移動幻燈片),幻燈片編號也會隨之更改。
注意:從技術上講,我可以對 Powerpoint 中的所有幻燈片進行 for 循環,並在左下角添加文本框以添加幻燈片編號,但這樣做,不精通技術的目標用戶將不得不手動更改頁碼如果他們更改 Powerpoint 中的任何內容,因為它只是一個文本框。
到目前為止,這是我想通的,但它不起作用。
Dim PPTApp As New PowerPoint.Application
Dim PPTPres As PowerPoint.Presentation
Dim ppt_template_path As String
ppt_template_path = "C:\Users\user\Documents\Performance Report Template.pptx"
PPTApp.Activate
Set PPTPres = PPTApp.Presentations.Open(ppt_template_path)
'---------this is where nothing happens when I try to enable Slide Number footers
If PPTPres.HasTitleMaster Then
With PPTPres.TitleMaster.HeadersFooters
.SlideNumber.Visible = msoTrue
End With
End If
With PPTPres.SlideMaster.HeadersFooters
.SlideNumber.Visible = msoTrue
End With
With PPTPres.Slides.Range.HeadersFooters
.SlideNumber.Visible = msoTrue
End With
順便說一句,我使用的是 Microsoft 365 版本。 所以我想知道你們是否有任何想法! 我真的很感激!
這是來自 PowerPoint 2003 宏記錄器的舊代碼(是的,PowerPoint 曾經有一個。)。 一些 VBA 從那以后發生了變化。 請注意在聲明中添加Dim oSlide as Slide :
Dim PPTApp As New PowerPoint.Application
Dim PPTPres As PowerPoint.Presentation
Dim ppt_template_path As String
Dim oSlide As Slide
ppt_template_path = "C:\Users\user\Documents\Performance Report Template.pptx"
PPTApp.Activate
Set PPTPres = PPTApp.Presentations.Open(ppt_template_path)
If PPTPres.HasTitleMaster Then
PPTPres.TitleMaster.HeadersFooters.SlideNumber.Visible = msoTrue
End If
PPTPres.SlideMaster.HeadersFooters.SlideNumber.Visible = msoTrue
For each oSlide in PPTPres.Slides
oSlide.HeadersFooters.SlideNumber.Visible = msoTrue
Next oSlide
使用Insert>Header & Footer>Slide number>Apply to All測試現有演示文稿是否可以打開幻燈片編號。 有很多模板,設計者從母版和布局中刪除了幻燈片編號占位符,使其無法實現。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.