MenuItemIDs.bas 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. ' CorelDRAW VBA自动化调用菜单命令的例子
  2. '过程名称:打印全部菜单ID(用于自动化调用)
  3. Public Sub listMenuItemIDs()
  4. On Error Resume Next
  5. Dim cmdbar, ctl
  6. For Each cmdbar In FrameWork.CommandBars
  7. Debug.Print cmdbar & "工具栏下面的菜单项:"
  8. For Each ctl In cmdbar.Controls
  9. Debug.Print vbTab & ctl.id & " -> " & ctl.Caption
  10. Next
  11. Next
  12. End Sub
  13. ' 拿到ID后,就可以通过自动化框架提供的方法来调用指定的菜单,参考代码如下:
  14. Sub 自动化调用()
  15. Dim OrigSelection As ShapeRange
  16. Set OrigSelection = ActiveSelectionRange
  17. OrigSelection.Application.FrameWork.Automation.InvokeItem "e6644135-9dab-4935-8ab9-fc85527810ca"
  18. End Sub
  19. Public Sub listMenuItemIDs_savefile()
  20. On Error Resume Next
  21. Set fs = CreateObject("Scripting.FileSystemObject")
  22. Set F = fs.CreateTextFile("D:\MenuItemIDs.txt", True)
  23. Dim cmdbar, ctl
  24. For Each cmdbar In FrameWork.CommandBars
  25. F.WriteLine cmdbar & "工具栏下面的菜单项:"
  26. For Each ctl In cmdbar.Controls
  27. F.WriteLine vbTab & ctl.id & " -> " & ctl.Caption
  28. Next
  29. Next
  30. F.Close
  31. End Sub