Option Explicit Sub 工具栏命令列表() Dim X As Byte Dim i As CommandBar, n As CommandBarControl, j As Paragraph, myrange As Range Dim A%, B%, s% Debug.Print Timer Application.ScreenUpdating = False '关闭屏幕更新 页眉页脚 制表位 Options.PictureWrapType = wdWrapMergeInline '图片设为嵌入型 For Each i In Application.CommandBars '在命令栏中循环 On Error Resume Next '忽略错误 A = A + 1 '命令栏计数器 Set myrange = ActiveDocument.Paragraphs.Last.Range myrange.Paragraphs.LeftIndent = CentimetersToPoints(0) '则左缩进为0 myrange.Font.Bold = True '而且加粗 myrange.InsertAfter A & "." & i.Name & vbCrLf For Each n In i.Controls '在命令栏i中的控件集合中循环 B = B + 1 '一级控件计数器 myrange.InsertAfter A & "." & B & vbTab & n.Caption & vbTab & "ID:=" & n.ID & vbTab Set myrange = ActiveDocument.Paragraphs.Last.Range myrange.Paragraphs.LeftIndent = CentimetersToPoints(1) '则左缩进为1 myrange.Font.Bold = False '不加粗 s = n.ID face (s) ActiveDocument.Words.Last.Paste '在最后一个位置粘贴 ' myrange.Paste myrange.InsertAfter Chr(13) '插入一个回车 On Error Resume Next '忽略错误 '忽略错误 Next B = 0 '复零 Next Application.ScreenUpdating = True '恢复屏幕更新 Debug.Print Timer Application.CommandBars("Standard").Controls(1).FaceId = 2520 '恢复第一个的“新建”默认图标 End Sub Sub 页眉页脚() Dim myrange As Range Dim range1 As Range With ActiveDocument.Sections(1) With .Headers(wdHeaderFooterPrimary).Range '设置页眉 .Text = "Word工具栏/命令列表" '页面上的文字 .Font.Name = "华文细黑" '文字的格式 .Font.Size = "16" .ParagraphFormat.Alignment = wdAlignParagraphCenter '居中对齐 End With Set myrange = .Footers(wdHeaderFooterPrimary).Range '设置页眉 NormalTemplate.AutoTextEntries("第 X 页 共 Y 页").Insert Where:=myrange '插入自动图文集中的域代码 myrange.ParagraphFormat.Alignment = wdAlignParagraphRight '页脚右对齐 End With End Sub Sub 制表位() With ActiveDocument.Paragraphs(1).TabStops .Add Position:=CentimetersToPoints(2.5) '2.5厘米处第一个制表位 .Add Position:=CentimetersToPoints(11) '11厘米处第一个制表位 .Add Position:=CentimetersToPoints(14) '14厘米处第一个制表位 End With End Sub Sub face(s As Integer) With Application.CommandBars("Standard").Controls(1) .FaceId = s '利用第一个图标来复制、粘贴 .CopyFace End With End Sub 没用selection的改进,也没有在段落中循环。速度稍快一点点。 |