VBA Word - 从文本中删除标题中的超链接

问题描述

我正在尝试删除特定范围内的所有标题(第 4 页,直到文档结束)。 我想删除只删除超链接,而不删除文本本身。

例如: Some text here -> 这里有一些文字 删除超链接标题后。

到目前为止我尝试过:

Sub removeCaptions()

  Dim rgePages As Range

  Selection.GoTo What:=wdGoToPage,Which:=wdGoToAbsolute,Count:=4
  Set rgePages = Selection.Range
  lastPage = ActiveDocument.ActiveWindow.Panes(1).Pages.Count
  Selection.GoTo What:=wdGoToPage,Count:=lastPage
  rgePages.End = Selection.Bookmarks("\Page").Range.End

  With rgePages.Select

      If Range.Style = "Caption" Then
         Range.Delete
      End If

  End With

End Sub

但我只得到范围而不删除标题。

提前致谢!

解决方法

例如:

Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = ""
    .Replacement.Text = ""
    .Format = True
    .Forward = True
    .Style = wdStyleCaption
    .Wrap = wdFindStop
  End With
  Do While .Find.Execute
    If .Information(wdActiveEndAdjustedPageNumber) > 3 Then .Fields.Unlink
    .Collapse wdCollapseEnd
  Loop
End With
Application.ScreenUpdating = True
End Sub

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...