ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 9262|回复: 11

[求助] 对于导航栏,如何进行默认 折叠处理。

[复制链接]

TA的精华主题

TA的得分主题

发表于 2013-7-30 15:25 | 显示全部楼层 |阅读模式
每次打开文档, 导航栏都是默认展开方式
如图

如何, 每次打开文档, 导航栏都是默认折叠方式
如图所示

谢谢

TA的精华主题

TA的得分主题

发表于 2013-7-30 23:23 | 显示全部楼层
点击视图-》文档结构图,去掉勾选即可。。。。。。

TA的精华主题

TA的得分主题

 楼主| 发表于 2013-8-2 12:50 | 显示全部楼层
amesman 发表于 2013-7-30 23:23
点击视图-》文档结构图,去掉勾选即可。。。。。。

并不是去掉导航图,而是默认折叠处理

TA的精华主题

TA的得分主题

 楼主| 发表于 2013-8-15 12:27 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2013-8-19 10:37 | 显示全部楼层
摸索了很长时间,请教了守柔版主,用api达到了目的,代码如下:
Const VK_1 = 49
Const KEYEVENTF_KEYUP = &H2
Const INPUT_MOUSE = 0
Const INPUT_KEYBOARD = 1
Const INPUT_HARDWARE = 2
Private Const MOUSEEVENTF_MOVE = &H1      '移动鼠标
Private Const MOUSEEVENTF_LEFTDOWN = &H2      ' 模拟鼠标左键按下
Private Const MOUSEEVENTF_LEFTUP = &H4   '模拟鼠标左键抬起
Private Const MOUSEEVENTF_RIGHTDOWN = &H8   '模拟鼠标右键按下
Private Const MOUSEEVENTF_RIGHTUP = &H10   ' 模拟鼠标右键抬起
Private Const MOUSEEVENTF_MIDDLEDOWN = &H20   '模拟鼠标中键按下
Private Const MOUSEEVENTF_MIDDLEUP = &H40     '模拟鼠标中键抬起
Private Const MOUSEEVENTF_ABSOLUTE = &H8000    '标示是否采用绝对坐标
Private Declare Function SendInput Lib "user32.dll" (ByVal nInputs As Long, pInputs As GENERALINPUT, ByVal cbSize As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
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 Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal Y As Long) As Long
Private Type POINTAPI
    x As Long
    Y As Long
End Type
Private Type MOUSEINPUT
  dx As Long
  dy As Long
  mouseData As Long
  dwFlags As Long
  time As Long
  dwExtraInfo As Long
End Type
Private Type KEYBDINPUT
  wVk As Integer
  wScan As Integer
  dwFlags As Long
  time As Long
  dwExtraInfo As Long
End Type
Private Type HARDWAREINPUT
  uMsg As Long
  wParamL As Integer
  wParamH As Integer
End Type
Private Type GENERALINPUT
  dwType As Long
  xi(0 To 23) As Byte
End Type
Private Sub SendKey(bKey As Byte)
    Dim GInput(0 To 1) As GENERALINPUT
    Dim KInput As KEYBDINPUT
    KInput.wVk = bKey  'the key we're going to press
    KInput.dwFlags = 0 'press the key
    'copy the structure into the input array's buffer.
    GInput(0).dwType = INPUT_KEYBOARD   ' keyboard input
    CopyMemory GInput(0).xi(0), KInput, Len(KInput)
    'do the same as above, but for releasing the key
    KInput.wVk = bKey  ' the key we're going to realease
    KInput.dwFlags = KEYEVENTF_KEYUP  ' release the key
    GInput(1).dwType = INPUT_KEYBOARD  ' keyboard input
    CopyMemory GInput(1).xi(0), KInput, Len(KInput)
    'send the input now
    Call SendInput(2, GInput(0), Len(GInput(0)))
End Sub
Private Sub Document_Open()
ss = Me.Name
ss = Split(Me.Name, ".")(0) & " - Microsoft Word"
    Dim hWnd1 As Long
    hWnd1 = FindWindow(vbNullString, ss)    '"SciCalc"
    Dim PP As POINTAPI
    PP.x = 96
    PP.Y = 515
    SetCursorPos PP.x, PP.Y
    mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0&, 0&
    mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0&, 0&
    SendKey VK_1
End Sub
使用方法:只需将此代码复制到目标文档的Thisdocument下即可。每次打开自动折叠为1级。
1.jpg
测试附件:
Doc1.rar (14.8 KB, 下载次数: 33)




TA的精华主题

TA的得分主题

发表于 2013-8-19 10:40 | 显示全部楼层
Const VK_1 = 49
Const KEYEVENTF_KEYUP = &H2
Const INPUT_MOUSE = 0
Const INPUT_KEYBOARD = 1
Const INPUT_HARDWARE = 2
Private Const MOUSEEVENTF_MOVE = &H1      '移动鼠标
Private Const MOUSEEVENTF_LEFTDOWN = &H2      ' 模拟鼠标左键按下
Private Const MOUSEEVENTF_LEFTUP = &H4   '模拟鼠标左键抬起
Private Const MOUSEEVENTF_RIGHTDOWN = &H8   '模拟鼠标右键按下
Private Const MOUSEEVENTF_RIGHTUP = &H10   ' 模拟鼠标右键抬起
Private Const MOUSEEVENTF_MIDDLEDOWN = &H20   '模拟鼠标中键按下
Private Const MOUSEEVENTF_MIDDLEUP = &H40     '模拟鼠标中键抬起
Private Const MOUSEEVENTF_ABSOLUTE = &H8000    '标示是否采用绝对坐标
Private Declare Function SendInput Lib "user32.dll" (ByVal nInputs As Long, pInputs As GENERALINPUT, ByVal cbSize As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
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 Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal Y As Long) As Long
Private Type POINTAPI
    x As Long
    Y As Long
End Type
Private Type MOUSEINPUT
  dx As Long
  dy As Long
  mouseData As Long
  dwFlags As Long
  time As Long
  dwExtraInfo As Long
End Type
Private Type KEYBDINPUT
  wVk As Integer
  wScan As Integer
  dwFlags As Long
  time As Long
  dwExtraInfo As Long
End Type
Private Type HARDWAREINPUT
  uMsg As Long
  wParamL As Integer
  wParamH As Integer
End Type
Private Type GENERALINPUT
  dwType As Long
  xi(0 To 23) As Byte
End Type
Private Sub SendKey(bKey As Byte)
    Dim GInput(0 To 1) As GENERALINPUT
    Dim KInput As KEYBDINPUT
    KInput.wVk = bKey  'the key we're going to press
    KInput.dwFlags = 0 'press the key
    'copy the structure into the input array's buffer.
    GInput(0).dwType = INPUT_KEYBOARD   ' keyboard input
    CopyMemory GInput(0).xi(0), KInput, Len(KInput)
    'do the same as above, but for releasing the key
    KInput.wVk = bKey  ' the key we're going to realease
    KInput.dwFlags = KEYEVENTF_KEYUP  ' release the key
    GInput(1).dwType = INPUT_KEYBOARD  ' keyboard input
    CopyMemory GInput(1).xi(0), KInput, Len(KInput)
    'send the input now
    Call SendInput(2, GInput(0), Len(GInput(0)))
End Sub
Private Sub Document_Open()
ss = Me.Name
ss = Split(Me.Name, ".")(0) & " - Microsoft Word"
    Dim hWnd1 As Long
    hWnd1 = FindWindow(vbNullString, ss)    '"SciCalc"
    Dim PP As POINTAPI
    PP.x = 96
    PP.Y = 515
    SetCursorPos PP.x, PP.Y
    mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0&, 0&
    mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0&, 0&
    SendKey VK_1
End Sub
复制到目标文档的thisdocument下保存即可。
测试文档:
Doc1.rar (14.8 KB, 下载次数: 11)

TA的精华主题

TA的得分主题

发表于 2013-8-19 10:41 | 显示全部楼层
本帖最后由 zhanglei1371 于 2013-8-19 10:42 编辑

奇怪,发的2贴都消失了...
难道论坛对这段代码敏感??》
附件如下:
Doc1.rar (14.8 KB, 下载次数: 30)

TA的精华主题

TA的得分主题

发表于 2013-8-19 10:44 | 显示全部楼层
再发一次代码:
  1. Const VK_1 = 49
  2. Const KEYEVENTF_KEYUP = &H2
  3. Const INPUT_MOUSE = 0
  4. Const INPUT_KEYBOARD = 1
  5. Const INPUT_HARDWARE = 2
  6. Private Const MOUSEEVENTF_MOVE = &H1      '移动鼠标
  7. Private Const MOUSEEVENTF_LEFTDOWN = &H2      ' 模拟鼠标左键按下
  8. Private Const MOUSEEVENTF_LEFTUP = &H4   '模拟鼠标左键抬起
  9. Private Const MOUSEEVENTF_RIGHTDOWN = &H8   '模拟鼠标右键按下
  10. Private Const MOUSEEVENTF_RIGHTUP = &H10   ' 模拟鼠标右键抬起
  11. Private Const MOUSEEVENTF_MIDDLEDOWN = &H20   '模拟鼠标中键按下
  12. Private Const MOUSEEVENTF_MIDDLEUP = &H40     '模拟鼠标中键抬起
  13. Private Const MOUSEEVENTF_ABSOLUTE = &H8000    '标示是否采用绝对坐标
  14. Private Declare Function SendInput Lib "user32.dll" (ByVal nInputs As Long, pInputs As GENERALINPUT, ByVal cbSize As Long) As Long
  15. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
  16. Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
  17. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  18. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
  19. 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
  20. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  21. Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  22. Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal Y As Long) As Long
  23. Private Type POINTAPI
  24.     x As Long
  25.     Y As Long
  26. End Type
  27. Private Type MOUSEINPUT
  28.   dx As Long
  29.   dy As Long
  30.   mouseData As Long
  31.   dwFlags As Long
  32.   time As Long
  33.   dwExtraInfo As Long
  34. End Type
  35. Private Type KEYBDINPUT
  36.   wVk As Integer
  37.   wScan As Integer
  38.   dwFlags As Long
  39.   time As Long
  40.   dwExtraInfo As Long
  41. End Type
  42. Private Type HARDWAREINPUT
  43.   uMsg As Long
  44.   wParamL As Integer
  45.   wParamH As Integer
  46. End Type
  47. Private Type GENERALINPUT
  48.   dwType As Long
  49.   xi(0 To 23) As Byte
  50. End Type
  51. Private Sub SendKey(bKey As Byte)
  52.     Dim GInput(0 To 1) As GENERALINPUT
  53.     Dim KInput As KEYBDINPUT
  54.     KInput.wVk = bKey  'the key we're going to press
  55.     KInput.dwFlags = 0 'press the key
  56.     'copy the structure into the input array's buffer.
  57.     GInput(0).dwType = INPUT_KEYBOARD   ' keyboard input
  58.     CopyMemory GInput(0).xi(0), KInput, Len(KInput)
  59.     'do the same as above, but for releasing the key
  60.     KInput.wVk = bKey  ' the key we're going to realease
  61.     KInput.dwFlags = KEYEVENTF_KEYUP  ' release the key
  62.     GInput(1).dwType = INPUT_KEYBOARD  ' keyboard input
  63.     CopyMemory GInput(1).xi(0), KInput, Len(KInput)
  64.     'send the input now
  65.     Call SendInput(2, GInput(0), Len(GInput(0)))
  66. End Sub
  67. Private Sub Document_Open()
  68. ss = Me.Name
  69. ss = Split(Me.Name, ".")(0) & " - Microsoft Word"
  70.     Dim hWnd1 As Long
  71.     hWnd1 = FindWindow(vbNullString, ss)    '"SciCalc"
  72.     Dim PP As POINTAPI
  73.     PP.x = 96
  74.     PP.Y = 515
  75.     SetCursorPos PP.x, PP.Y
  76.     mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0&, 0&
  77.     mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0&, 0&
  78.     SendKey VK_1
  79. End Sub
复制代码

代码粘贴到目标文档的thisdocument下即可。

TA的精华主题

TA的得分主题

 楼主| 发表于 2013-9-6 09:13 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
谢谢了,我去试一下

TA的精华主题

TA的得分主题

发表于 2017-6-11 15:03 | 显示全部楼层
为什么我下载了测试的附件,或者直接拷代码到我的文档试了下都不行呢
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2025-1-12 23:01 , Processed in 0.027405 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表