vba - VBA代码不适用于删除ppt幻灯片
问题描述
我正在尝试使用特定的关键字删除 ppt 幻灯片。我的代码如下:
Private Sub CommandButton1_Click()
Dim strFileName As String
Dim strFolderName As String
Dim PP As Presentation
Dim ppMaster
Dim sText As Variant
strFolderName = "D:\Shaon_Paul\pptss"
strFileName = Dir(strFolderName & "\*.pptx*")
sText = InputBox("Give me some input")
Do While Len(strFileName) > 0
Set PP = Presentations.Open(strFolderName & "\" & strFileName)
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
On Error Resume Next
If oShp.HasTextFrame Then
If UBound(Split(oShp.TextFrame.TextRange, sText)) > 0 Then
PP.Slides(L).Delete
End If
End If
Next oShp
Next L
Set ppMaster = PP.SlideMaster
With ppMaster
If UBound(Split(.HeadersFooters.Footer.Text, sText)) > 0 Or UBound(Split(.HeadersFooters.Header.Text, sText)) > 0 Then
PP.Slides(L).Delete
End If
End With
PP.Save
PP.Close
strFileName = Dir
Loop
End Sub
现在这段代码将打开一个输入框,我必须在其中输入关键字,它将删除我提到路径名的文件夹中可用的 ppt 中的幻灯片。不幸的是,在调试代码时
If UBound(Split(oShp.TextFrame.TextRange, sText)) > 0 Then
PP.Slides(L).Delete
End If
它会在不执行上面的代码的情况下跳转,并且无法通过给出特定的关键字名称来删除幻灯片。需要帮助来解决此问题。
解决方案
推荐阅读
- python - Is it possible to override request payload in python?
- html - Hover zoom behavior not working as I expected on img tag inside span tag
- gcc - Which versions of GCC and clang support std::filesystem/std::experimental::filesystem?
- vba - 在这种情况下,从用户窗体访问集合的最佳方式是什么?
- ios - 在 SwiftUI 中使用 DragGesture() 计算的高度不正确
- javascript - bootstrap通过js获取输入复选框的值
- python - How to Loop Through Dates in Python to pass into PostgresSQL query
- android - Flutter Event Channel Stream 导致应用程序崩溃(与设备的连接丢失)
- css - CSS动画侧面板
- r - dplyr::if_else 是否同时评估 TRUE 和 FALSE?