[英]Removing unused master slide of multiples powerpoint files using Excel VBA
Hello Stackoverflow community,你好 Stackoverflow 社区,
I wish to remove unused masterslides from multiples powerpoint presentation.我希望从多个 powerpoint 演示文稿中删除未使用的 masterslides。 The list of files is in an excel file.文件列表位于 excel 文件中。 I wrote a macro that opens each powerpoint files.我写了一个宏来打开每个 powerpoint 文件。 I found a macro that used within powerpoint VBA removes unused masterslide but doesn't work when I include it in my Excel macro... Also I don't manage to save and close each pwp files.我发现一个在 powerpoint VBA 中使用的宏删除了未使用的 masterslide,但是当我将它包含在我的 Excel 宏中时它不起作用......而且我无法保存和关闭每个 pwp 文件。
Macro that loops through files:循环文件的宏:
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
Macro that works when used directly in pwp:直接在 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
What could I do in order to:我该怎么做才能:
Thanks a lot非常感谢
Here's a first shot at revising your code.这是修改代码的第一步。 Give it a try;试试看; if it works, great.如果它有效,那就太好了。 If not, let us know what went wrong, and on what line of code.如果没有,请告诉我们出了什么问题,以及在哪一行代码。 Use this ONLY on a copy of your presentation(s).仅在您的演示文稿副本上使用它。 I don't see where you've coded any way of determining whether a layout is used or not.我看不到您在哪里编写了任何确定是否使用布局的方法。
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.