★★☆ 导航窗格,右键增加“选中此标题下内容”

有网友希望加入这个功能就好了

关于导航窗格全选某标题内容问题,我曾经发过一篇文章,详见:

https://bbs.wps.cn/topic/65953

★ 如何快速选中某一章节的标题和文字

但是上文仅仅是操作流程上的变通,并没有根本解决问题,每次都需要手动拖动、选择,也并不方便。

因此本文着重解决,直接将命令内嵌至命令菜单问题。

WPS右键命令在:版本号\office6\res\commands\wps\PopupMenu.kuip 下

这一段就是左侧目录的右键命令

在这里面加是最对路子,一劳永逸的。但是我并不清楚WPS内置全选目录命令是什么,盲猜几个也无效,添加自定义命令也并未成功,因此放弃。

幸好方法也不止一种,直接用VBA宏:

可以加到快速启动栏,

但是还是一步到位,直接加到右键菜单。

宏命令如下,直接复制:

Private Sub Document_Open()

On Error Resume Next

CommandBars("NavigationPane DocMapView Popup Menu").Controls( _

"选中目录及子内容(&C)").Delete

On Error GoTo 0

Dim customBtn As CommandBarButton

Set customBtn = CommandBars("NavigationPane DocMapView Popup Menu").Controls.Add( _

Type:=msoControlButton)

customBtn.OnAction = "SelectDirWithAllContent"

customBtn.Caption = "选中目录及子内容(&C)"

customBtn.FaceId = 11

customBtn.Style = msoButtonIconAndCaption

End Sub

Sub SelectDirWithAllContent()

On Error Resume Next

Dim currStyleLevel As Integer

currStyleLevel = Selection.Paragraphs(1).Style.ParagraphFormat.OutlineLevel

Dim startPos As Long, endPos As Long

startPos = Selection.Paragraphs(1).Range.Start

endPos = startPos

Dim currPara As Paragraph

Set currPara = Selection.Paragraphs(1)

Do While Not currPara.Next Is Nothing

Set currPara = currPara.Next

If currPara.Style.ParagraphFormat.OutlineLevel > currStyleLevel Then

endPos = currPara.Range.End

ElseIf currPara.Style.ParagraphFormat.OutlineLevel <= currStyleLevel And _

Len(Trim(currPara.Range.Text)) > 0 Then

Exit Do

End If

Loop

If endPos = startPos Then

Selection.Paragraphs(1).Range.Select

Else

ActiveDocument.Range(startPos, endPos).Select

End If

On Error GoTo 0

Set currPara = Nothing

End Sub

可以把宏加入模板文件,这样就不用每次都重新加载。

然后保存,关闭。重新打开任一WPS文档,自动加载。

见图,最后一项,文字可改,右键热键字母C(可改),图标可改(原图标ID:11)

选中即是选中目录下所有文字

安徽省
浏览 208
2
4
分享
4 +1
3
2 +1
全部评论 3
 
user_19042982
不好意思刚看到C热键重复了,可换成S,左手适用,微软同款。
· 安徽省
回复
 
Esc2Exit
这个功能确实很实用,官方加进来最好了。有js宏最好了,现在自己再用的都是js宏
· 河北省
1
回复
 
风清月霁
风清月霁

WPS寻令官 | WPS产品体验官

点赞宏创作大佬
· 河南省
1
回复