网站首页 美食营养 游戏数码 手工爱好 生活家居 健康养生 运动户外 职场理财 情感交际 母婴教育 时尚美容 知识问答

word文档添加返回目录悬浮按钮的方法

时间:2024-10-13 03:52:02

1、ALT+F11打开VBE编辑器,在工程窗口右键-插入-用户窗体,插入一个新窗体UserForm1。

word文档添加返回目录悬浮按钮的方法

3、利用标签控件在窗体上拖拉出一个标签Label1。

word文档添加返回目录悬浮按钮的方法

5、在窗体UserForm1代码窗口粘贴入下代码:Private Declare Function GetWindowLong L足毂忍珩ib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As LongPrivate Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongPrivate Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPrivate Declare Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As LongPrivate 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 LongPrivate Const GWL_STYLE As Long = (-16)Private Const WS_CAPTION As Long = &HC00000Private Const WM_NCLBUTTONDOWN = &HA1Private Const HTCAPTION = 2Private Sub Label1_Click()Selection.HomeKey unit:=wdStory '返回文档开头Selection.MoveDown unit:=wdLine, Count:=9 '笔者此处演示文档,目录位置是位于文档开头往下数9行,具体可以根据需要自行更改End SubPrivate 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) + 50End SubPrivate 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

word文档添加返回目录悬浮按钮的方法
© 2025 小知经验
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com