在word中,按ctrl点击一个目录后,会导航到相应的段落,这时如何快速的回到目录呢?
方法一:
1, 按Alt+向左方向键 回到原目录。
2. 按Ctrl + home,回到文章开头。
方法二:
利用VBA给word文档添加一个悬浮按钮,只需鼠标单击该按钮就能跳转回文档的目录。
-
ALT+F11打开VBE编辑器,在工程窗口右键-插入-用户窗体,插入一个新窗体UserForm1。
-
在窗体属性对话框将:ShowModel属性设为False即将窗体设为无模态窗体,BorderStyle属性设为0-fmBorderStyleNone即将窗体设为无边框,StartUpPosition属性设为0-手动即将窗体的初始显示位置设置成手动更改,其余属性请按需更改。
-
利用标签控件在窗体上拖拉出一个标签Label1。
-
将标签Label1的Caption属性设为返回目录,BorderStyle属性设为0-fmBorderStyleNone,其余属性按需设置即可。
-
在窗体UserForm1代码窗口粘贴入下代码:
Private Declare Function GetWindowLong Lib “user32” Alias “GetWindowLongA” (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib “user32” Alias “SetWindowLongA” (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function FindWindow Lib “user32” Alias “FindWindowA” (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function DrawMenuBar Lib “user32” (ByVal hWnd As Long) As Long
Private Declare Sub ReleaseCapture Lib “user32” ()
Private Declare Function SendMessage Lib “user32” Alias “SendMessageA” (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const GWL_STYLE As Long = (-16)
Private Const WS_CAPTION As Long = &HC00000
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2
Private Sub Label1_Click()
Selection.HomeKey unit:=wdStory ‘返回文档开头
Selection.MoveDown unit:=wdLine, Count:=9 ‘笔者此处演示文档,目录位置是位于文档开头往下数9行,具体可以根据需要自行更改
End Sub
Private Sub UserForm_Initialize()
Dim lngStyle As Long
Dim hWnd As Long
hWnd = FindWindow(vbNullString, Me.Caption)
lngStyle = GetWindowLong(hWnd, GWL_STYLE)
SetWindowLong hWnd, GWL_STYLE, lngStyle And Not WS_CAPTION
DrawMenuBar hWnd
Me.Height = 31.5
Me.Left = Selection.Information(wdHorizontalPositionRelativeToPage) + 545
Me.Top = Selection.Information(wdVerticalPositionRelativeToPage) + 50
End Sub
Private Sub Label1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim hWnd As Long
hWnd = FindWindow(vbNullString, Me.Caption)
ReleaseCapture
SendMessage hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End Sub
-
在ThisDocument代码窗口粘贴如下代码:
Private Sub Document_Open()
UserForm1.Show
End Sub
注意:将代码Selection.MoveDown unit:=wdLine, Count:=9中的数字9更改为你需要跳转到的行即可。
方法三:
可以通过web工具条上面的“往返”按钮来操作。 如果一篇长文档,目录是自动生成的,点击目录条目进入所在位置操作,然后想要快速返回目录,可以打开web工具栏,点击个该工具栏中的“往返”按钮(就是标记为箭头那两个)。 调出web工具栏的方法:菜单→视图→工具栏→勾选web。也可以把鼠标放到工具栏空白处,击右键,选择web。 当然,也可以把这两个按钮定制到常用工具栏中以方便应用(方法:自定义→命令→找到后拖到工具栏)。