在word中列出宏

时间:2015-11-03 17:19:47

标签: vba ms-word word-vba

我正在尝试列出所有命令以及它们在Microsoft Word中分配的密钥。但是我遇到的问题只是列出我所做的宏/命令,而不是软件的那些;例如File SavePrintPreviewAndPrint

我目前使用的宏是;

Sub ListKeyboardAssignments()
  Dim kb As KeyBinding
  For Each kb In KeyBindings
    If kb.KeyCategory = wdKeyCategoryNil Then
      Selection.TypeText (kb.Command + " " + kb.KeyString + " //Nil")
      Selection.TypeParagraph
    End If
  Next kb
  For Each kb In KeyBindings
    If kb.KeyCategory = wdKeyCategoryDisable Then
      Selection.TypeText (kb.Command + " " + kb.KeyString + " //Disable")
      Selection.TypeParagraph
    End If
  Next kb
  For Each kb In KeyBindings
    If kb.KeyCategory = wdKeyCategoryCommand Then
      Selection.TypeText (kb.Command + " " + kb.KeyString + " //Command")
      Selection.TypeParagraph
    End If
  Next kb
  For Each kb In KeyBindings
    If kb.KeyCategory = wdKeyCategoryMacro Then
      Selection.TypeText (kb.Command + " " + kb.KeyString + " //Macro")
      Selection.TypeParagraph
    End If
  Next kb
  For Each kb In KeyBindings
    If kb.KeyCategory = wdKeyCategoryMacro Then
      Selection.TypeText (kb.Command + " " + kb.KeyString + " //Prefix")
      Selection.TypeParagraph
    End If
  Next kb
  For Each kb In KeyBindings
    If kb.KeyCategory = wdKeyCategoryFont Then
      Selection.TypeText (kb.Command + " " + kb.KeyString + " //Font")
      Selection.TypeParagraph
    End If
  Next kb
  For Each kb In KeyBindings
    If kb.KeyCategory = wdKeyCategoryAutoText Then
      Selection.TypeText (kb.Command + " " + kb.KeyString + " //AutoText")
      Selection.TypeParagraph
    End If
  Next kb
  For Each kb In KeyBindings
    If kb.KeyCategory = wdKeyCategoryStyle Then
      Selection.TypeText (kb.Command + " " + kb.KeyString + " //Style")
      Selection.TypeParagraph
    End If
  Next kb
  For Each kb In KeyBindings
    If kb.KeyCategory = wdKeyCategorySymbol Then
      Selection.TypeText (kb.Command + " " + kb.KeyString + " //Symbol")
      Selection.TypeParagraph
    End If
  Next kb
  For Each kb In KeyBindings
    If kb.KeyCategory = wdKeyCategoryPrefix Then
      Selection.TypeText (kb.Command + " " + kb.KeyString + " //Prefix")
      Selection.TypeParagraph
    End If
  Next kb
End Sub

修改

这个宏也没有列出我所做的宏/命令的所有宏。任何帮助解决这个问题将非常感谢

1 个答案:

答案 0 :(得分:1)

KeyBindings仅提及您的自定义快捷方式。

如果您只想要所有基于标准单词的快捷方式的表,那么您想要使用:

 Application.ListCommands ListAllCommands:=True

这将打开一个新文档,然后使用命令名称和键串插入一个表。