Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 在选定幻灯片中添加或替换幻灯片编号';标题_Vba_Powerpoint - Fatal编程技术网

Vba 在选定幻灯片中添加或替换幻灯片编号';标题

Vba 在选定幻灯片中添加或替换幻灯片编号';标题,vba,powerpoint,Vba,Powerpoint,我想创建宏,该宏将以格式(1/5)添加到所选幻灯片标题的末尾 我已经设法用添加编号来写那部分了。我无法准备vba以查找和替换现有编号。无论出于何种原因,幻灯片顺序将发生更改并需要更新时,都需要使用该选项 Sub-SlideNumbering() 将shp变暗为形状 将sld变暗为幻灯片 将SldAll设置为单个 单条尺寸SldNr SldAll=Application.ActiveWindow.Selection.SlideRange.Count SldNr=SldAll 对于s=SldAll至

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

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

Sub-SlideNumbering()
将shp变暗为形状
将sld变暗为幻灯片
将SldAll设置为单个
单条尺寸SldNr
SldAll=Application.ActiveWindow.Selection.SlideRange.Count
SldNr=SldAll
对于s=SldAll至1步骤-1
ActivePresentation.Slides.Shapes.Title.TextFrame.TextRange.InsertAfter“(“&SldNr&“/”&SldAll&“)
SldNr=SldNr-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

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