excel - 为其他 PPT 运行 Power Point 宏代码
问题描述
我有一个名为“KillSpecificSlide”的宏代码用于 power point。此代码在 ppt 后面运行。如果我想将相同的代码复制到另一个 ppt,或者如果我想将代码从一个 PPT 运行到其他一些不同的 PPT,那么如何做到这一点?
我的代码如下:
Sub KillSpecificSlide()
Dim oSld As Slide
Dim oShp As Shape
Dim L As Long
For L = ActivePresentation.Slides.Count To 1 Step -1
Set oSld = ActivePresentation.Slides(L)
For Each oShp In oSld.Shapes
If oShp.HasTextFrame Then
Select Case UCase(oShp.TextFrame.TextRange)
Case Is = "Q4", "CJ"
oSld.Delete
Case Else
'not found
End Select
End If
Next oShp
Next L
End Sub
这保存在名为 BOX.pptm 的 PPT 的模块 1 中。我想通过浏览它来为其他 ppt 文件运行相同的代码。
Sub PPTTest()
Dim PPT As Object
Set PPT = CreateObject("PowerPoint.Application")
PPT.Presentations.Open "D:\Us\70\Desktop\Shaon\BOD.pptx", , , False
' Note that the file name and the module
' name are required to path the macro correctly.
PPT.Run "BOD.pptx!Module1.KillSpecificSlide"
End Sub
解决方案
Option Explicit
Sub listOpenPresentations()
Dim myPpt As Presentation
Debug.Print "Open ppt's : "; Application.Presentations.Count & vbCrLf
For Each myPpt In Application.Presentations
Debug.Print myPpt.Name
Call Add_and_Delete_Slide(myPpt)
Next myPpt
End Sub
Sub Add_and_Delete_Slide(locPPT As Presentation)
Dim pptSlide As Slide
Dim pptLayout As CustomLayout
Dim actWindow As Variant
For Each actWindow In Windows
If actWindow.Caption = locPPT.Name Then actWindow.Activate
Next actWindow
Set pptLayout = ActivePresentation.Slides(1).CustomLayout
Set pptSlide = ActivePresentation.Slides.AddSlide(2, pptLayout)
MsgBox "Slide 2 added in """ & ActivePresentation.Name & """"
ActivePresentation.Slides(2).Delete
MsgBox "Slide 2 deleted in """ & ActivePresentation.Name & """"
End Sub
推荐阅读
- java - 获取一年中的第 n 天
- android - 上传音频文件时,API 在邮递员中工作,但在 android 应用程序中不工作
- python - 处理具有多个根元素的大型 JSON 并读入 pandas 数据帧
- karate - Karate-config.js,是否可以在每个空手道场景之后运行 java 方法?
- python - 批量插入,更新值 mongodb
- regex - 如何用另一个文件中的组(已知正则表达式)替换一个文件中的空白空间?
- php - 如何按 ACF 字段查询帖子,然后按单独的 ACF 字段排序?
- scroll - Ionic 4 + 水平滚动 + ion-split-pane 导致 Angular Material 的拖放错误
- flutter - 颤动中的透明容器
- ubuntu - 使用 pcap_next_ex() 可以很好地捕获,但以太网标头大小不同。14 个使用 Ubuntu,4 个使用 FreeBSD