【问题标题】:Adding or replacing slide numbering in selected slides' titles在所选幻灯片的标题中添加或替换幻灯片编号
【发布时间】:2019-10-31 01:00:17
【问题描述】:

我想创建一个宏,它将添加到所选幻灯片标题的末尾,格式为 (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

【问题讨论】:

  • 处理这种情况的最简单方法是编写一个单独的 mecro 来擦除所有编号。然后你的宏总是以空白画布开始。
  • 好的,但如果我不知道数字,我仍然不知道该怎么做如何选择字符串中包含“(”“)”和未知内容之间的文本范围?

标签: vba powerpoint


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2022-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-15
    • 2017-12-31
    • 2022-09-30
    • 2022-01-24
    • 2023-02-05
    相关资源
    最近更新 更多