在所选幻灯片的标题中添加或替换幻灯片编号

Adding or replacing slide numbering in selected slides' titles

我想创建宏,将添加到所选幻灯片标题的末尾,格式为 (1/5)。

我已经设法通过添加编号来编写该部分。我无法准备 vba 来查找和替换现有编号。无论出于何种原因,幻灯片顺序将更改并需要更新时,都需要它。

Sub SlideNumbering()

Dim shp As shape
Dim sld As Slide
Dim SldAll As Single
Dim SldNr As Single

SldAll = Application.ActiveWindow.Selection.SlideRange.Count

SldNr = SldAll

For s = SldAll To 1 Step -1
    ActivePresentation.Slides(s).Shapes.Title.TextFrame.TextRange.InsertAfter " (" & SldNr & "/" & SldAll & ")"
    SldNr = SldNr - 1
Next

End Sub

这是删除现有编号的宏。这使用正则表达式模式查找 space、括号、任意数字、反斜杠、任意数字和右括号的序列:

Sub DeleteNumbering()
  Dim regX As Object
  Dim oSlide As Slide
  Dim oShape As Shape
  Dim Foundb As Boolean
  Dim NewText$

  Set regX = CreateObject("vbscript.regexp")
  With regX
    .Global = True
    .Pattern = " \(\d(/)\d\)"
  End With
  ReplaceWord = ""

  For Each oSlide In ActivePresentation.Slides
    For Each oShape In oSlide.Shapes
      If oShape.Type = msoPlaceholder Then
        If (oShape.PlaceholderFormat.Type = ppPlaceholderCenterTitle _
        Or oShape.PlaceholderFormat.Type = ppPlaceholderTitle) _
        And oShape.TextFrame.HasText Then
          Foundb = regX.Test(oShape.TextFrame.TextRange.Text)
          If Foundb = True Then
            NewText$ = regX.Replace(oShape.TextFrame.TextRange.Text, "")
            oShape.TextFrame.TextRange.Text = NewText$
          End If
        End If
      End If
    Next oShape
  Next oSlide
End Sub