|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
可试试如下代码(仅适用于MS word):
- Sub test1()
- '在大纲视图下删除标题3及其所属下级段落内容,仅MS Word中
- Dim i%
- Application.ScreenUpdating = False
- With ActiveDocument.ActiveWindow.View
- i = .Type
- If i <> 2 Then .Type = wdOutlineView
- .ShowHeading 3
- With Selection
- .EndKey wdStory
- Do
- '可用标题样式或大纲级别作判断
- If .Style = "标题 3" Then ActiveDocument.Content.Bookmarks("\HeadingLevel").Range.Delete
- Loop Until .MoveUp(wdParagraph) = 0
- End With
- If i <> 2 Then .Type = i
- End With
- Application.ScreenUpdating = True
- End Sub
复制代码
如用在WPS,可试试
- Sub test2()
- '在大纲视图下删除标题3及其所属下级段落内容,仅WPS
- Dim i%, j%, n%, rngstart&, rngend&
- Application.ScreenUpdating = False
- With ActiveDocument.ActiveWindow.View
- i = .Type
- If i <> 2 Then .Type = wdOutlineView
- .ShowHeading 3
- With Selection
- .EndKey wdStory
- rngend = ActiveDocument.Content.End
- Do
- .StartOf wdParagraph
- If .ParagraphFormat.OutlineLevel = wdOutlineLevel3 Then
- ActiveDocument.Range(.Start, IIf(rngend > 0, rngend, rngstart)).Delete
- j = j + 1
- rngend = 0
- rngstart = .Start
- ElseIf .ParagraphFormat.OutlineLevel < 3 Then
- rngend = .Start
- End If
- n = .MoveUp(wdParagraph)
- Loop Until n = 0
- End With
- If i <> 2 Then .Type = i
- End With
- MsgBox "共删除了" & j & "个区域。"
- Application.ScreenUpdating = True
- End Sub
复制代码
考虑到只是大纲,只用moveup方法循环,均未作详细测试,也许有更快捷的方法。 |
评分
-
1
查看全部评分
-
|