[英]Removing unused master slide of multiples powerpoint files using Excel VBA
你好 Stackoverflow 社區,
我希望從多個 powerpoint 演示文稿中刪除未使用的 masterslides。 文件列表位於 excel 文件中。 我寫了一個宏來打開每個 powerpoint 文件。 我發現一個在 powerpoint VBA 中使用的宏刪除了未使用的 masterslide,但是當我將它包含在我的 Excel 宏中時它不起作用......而且我無法保存和關閉每個 pwp 文件。
循環文件的宏:
Dim myPresentation As Object
Dim PowerPointApp As Object
Set myPresentation = CreateObject("Powerpoint.application")
'Find last row of path files list
lastRow = Cells(Rows.Count, "A").End(xlUp).Row
'Looping through files
For i = 1 To lastRow
'Defines pwp file to open
DestinationPPT = Cells(i, "A")
'opens pwp file
myPresentation.presentations.Open DestinationPPT
myPresentation.Visible = True
'Then I would like to : remove unused master slide, save, close
Next i
End Sub
直接在 pwp 中使用時起作用的宏:
Sub SlideMasterCleanup()
Dim k As Integer
Dim n As Integer
Dim oPres As Presentation
Set oPres = ActivePresentation
On Error Resume Next
With oPres
For k = 1 To .Designs.Count
For n = .Designs(k).SlideMaster.CustomLayouts.Count To 1 Step -1
.Designs(k).SlideMaster.CustomLayouts(n).Delete
Next
Next k
End With
End Sub
我該怎么做才能:
非常感謝
這是修改代碼的第一步。 試試看; 如果它有效,那就太好了。 如果沒有,請告訴我們出了什么問題,以及在哪一行代碼。 僅在您的演示文稿副本上使用它。 我看不到您在哪里編寫了任何確定是否使用布局的方法。
Option Explicit
Sub Main()
Dim myPresentation As Object
Dim PowerPointApp As Object
Set PowerPointApp = CreateObject("Powerpoint.application")
'Find last row of path files list
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
'Looping through files
For i = 1 To LastRow
'Defines pwp file to open
DestinationPPT = Cells(i, "A")
'opens pwp file
Set myPresentation = PowerPointApp.Presentations.Open(DestinationPPT)
myPresentation.Visible = True
'Then I would like to : remove unused master slide, save, close
Call SlideMasterCleanup(myPresentation)
Next i
End Sub
Sub SlideMasterCleanup(oPres As Presentation)
Dim k As Integer
Dim n As Integer
On Error Resume Next
With oPres
For k = 1 To .Designs.Count
For n = .Designs(k).SlideMaster.CustomLayouts.Count To 1 Step -1
.Designs(k).SlideMaster.CustomLayouts(n).Delete
Next
Next k
End With
oPres.Save
oPres.Close
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.