Advertisement
Alexislls

Macro Shortcut Word

Jul 22nd, 2019
1,001
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  'Creado por WordDesdeCero.es.
  2. Option Explicit
  3. Sub ListCompositeShortcuts()
  4. Dim oDoc As Word.Document
  5. Dim oDocTemp As Word.Document
  6. Dim oKey As KeyBinding
  7. Dim oTbl_1 As Word.Table, oTbl_2 As Word.Table
  8. Dim oRng As Word.Range
  9. Dim lngIndex As Long
  10. Dim oRow As Word.Row
  11.  
  12.   'Create a new document for listing composite shortcuts.
  13.  Set oDoc = Documents.Add(, , wdNewBlankDocument)
  14.   Set oRng = oDoc.Range
  15.   System.Cursor = wdCursorWait
  16.   Application.ScreenUpdating = False
  17.   CustomizationContext = NormalTemplate 'or the template\document to evaluate.
  18.  'List and sort custom keybindings.
  19.  For lngIndex = 1 To KeyBindings.Count
  20.     Set oKey = KeyBindings(lngIndex)
  21.     oRng.InsertAfter vbCr & oKey.KeyCategory & vbTab & oKey.Command _
  22.                    & vbTab & oKey.KeyString
  23.     'Update status bar.
  24.    Application.StatusBar = "Processing custom keybinding " & lngIndex & " of " & _
  25.                              KeyBindings.Count & ".  Please wait."
  26.     DoEvents
  27.   Next lngIndex
  28.   'Show progress to user.
  29.  With Application
  30.     .ScreenUpdating = True
  31.     .ScreenRefresh
  32.     .ScreenUpdating = False
  33.   End With
  34.   'Convert text to table or create table. Leave empty paragraph beginning the document.
  35.  oRng.MoveStart wdParagraph, 1
  36.   If Len(oRng.Text) > 2 Then
  37.     Set oTbl_1 = oRng.ConvertToTable
  38.   Else
  39.     Set oTbl_1 = oRng.Tables.Add(oRng, 2, 3)
  40.   End If
  41.   'Format table.
  42.  With oTbl_1
  43.     .Style = "Tabla con cuadrícula 1 clara"
  44.     .Range.NoProofing = True
  45.     With .Rows
  46.       .Add BeforeRow:=oTbl_1.Rows(1)
  47.       .Add BeforeRow:=oTbl_1.Rows(1)
  48.     End With
  49.     With .Rows(1)
  50.       .HeadingFormat = True
  51.       With .Range
  52.       .Cells.Merge
  53.         With .Cells(1).Range
  54.           .ParagraphFormat.Alignment = wdAlignParagraphCenter
  55.           .Text = ": Configuración actual del teclado | Teclas personalizadas"
  56.           .Font.Bold = True
  57.         End With
  58.       End With
  59.     End With
  60.     With .Rows(2)
  61.       .HeadingFormat = True
  62.       .Shading.BackgroundPatternColor = wdColorGray10
  63.       .Cells(1).Range.Text = "Categoría"
  64.       .Cells(2).Range.Text = "Nombre/Símbolo"
  65.       .Cells(3).Range.Text = "Combinación de teclas de acceso directo"
  66.     End With
  67.     For lngIndex = 3 To .Rows.Count
  68.       Select Case Left(.Rows(lngIndex).Cells(1).Range.Text, _
  69.              Len(.Rows(lngIndex).Cells(1).Range.Text) - 2)
  70.         Case "1": .Rows(lngIndex).Cells(1).Range.Text = "Command"
  71.         Case "2": .Rows(lngIndex).Cells(1).Range.Text = "Macro"
  72.         Case "3": .Rows(lngIndex).Cells(1).Range.Text = "Font"
  73.         Case "4": .Rows(lngIndex).Cells(1).Range.Text = "BuildingBlock\AutoText"
  74.         Case "5": .Rows(lngIndex).Cells(1).Range.Text = "Style"
  75.         Case "6": .Rows(lngIndex).Cells(1).Range.Text = "Symbol"
  76.       End Select
  77.     Next lngIndex
  78.     'Sort on category.
  79.    .Sort True, 1
  80.   End With
  81.   'Add and format document title.
  82.  With oDoc.Paragraphs(1).Range
  83.     .InsertBefore "Lista compuesta de accesos directos"
  84.     .Style = "Título 1"
  85.   End With
  86.   'Show progress to user.
  87.  With Application
  88.     .ScreenUpdating = True
  89.     .ScreenRefresh
  90.     .ScreenUpdating = False
  91.   End With
  92.   'Add paragraph separator.
  93.  oRng.InsertAfter vbCr
  94.   oRng.Collapse wdCollapseEnd
  95.   'Create the built-in list using the Word command.
  96.  Application.ListCommands ListAllCommands:=0
  97.   'This creates a new active document.
  98.  Set oDocTemp = ActiveDocument
  99.   'Clean up Word 2003 list.
  100.  With Application
  101.     If .Version < 12# Then
  102.       .ScreenUpdating = True
  103.       .ScreenRefresh
  104.       .ScreenUpdating = False
  105.       .StatusBar = "Processing temporary list.  Please wait"
  106.       With oDocTemp.Tables(1)
  107.         .Columns(4).Delete
  108.         For lngIndex = oDocTemp.Tables(1).Rows.Count To 1 Step -1
  109.           Set oRow = oDocTemp.Tables(1).Rows(lngIndex)
  110.           If Len(oRow.Cells(2).Range) = 2 Then
  111.             oRow.Delete
  112.           End If
  113.           DoEvents
  114.         Next lngIndex
  115.       End With
  116.     End If
  117.   End With
  118.   'Get the list (table) and kill the document.
  119.  oDocTemp.Range.Copy
  120.   oDocTemp.Close wdDoNotSaveChanges
  121.   'Ensure the composite list is the active document.
  122.  oDoc.Activate
  123.   'Paste the copied table into the composite list.
  124.  oRng.Paste
  125.   Set oTbl_2 = oDoc.Tables(2)
  126.   'Format table.
  127.  With oTbl_2
  128.     .Style = "Tabla con cuadrícula 1 clara"
  129.     With .Range
  130.       .Font.Bold = False
  131.       .NoProofing = True
  132.     End With
  133.     .PreferredWidthType = wdPreferredWidthPercent
  134.     .PreferredWidth = 100
  135.     .Rows.Add BeforeRow:=oTbl_2.Rows(1)
  136.      With .Rows(1)
  137.       .HeadingFormat = True
  138.       With .Range
  139.         .Cells.Merge
  140.         With .Cells(1).Range
  141.           .ParagraphFormat.Alignment = wdAlignParagraphCenter
  142.           .Text = "Configuración actual del teclado -  Comandos Word incorporados"
  143.           .Font.Bold = True
  144.         End With
  145.       End With
  146.     End With
  147.     For lngIndex = 2 To .Rows.Count
  148.       Application.StatusBar = "Processing built-in keybinding " & lngIndex - 1 _
  149.                               & " of " & oTbl_2.Rows.Count - 1 & ".  Please wait."
  150.       With .Rows(lngIndex)
  151.         .Cells(2).Merge .Cells(3)
  152.         .Cells(2).Range.Text = Replace(.Cells(2).Range.Text, vbCr, "")
  153.       End With
  154.       DoEvents
  155.     Next lngIndex
  156.     With .Rows(2)
  157.       .HeadingFormat = True
  158.       .Shading.BackgroundPatternColor = wdColorGray10
  159.       .Cells(1).Range.Text = "Nombre del comando"
  160.       .Cells(2).Range.Text = "Combinación de teclas de acceso directo"
  161.     End With
  162.     .Range.Cells.DistributeWidth
  163.   End With
  164.   'Prevent (or try to prevent) a blank page at end of document.
  165.  Do While Len(oDoc.Paragraphs.Last.Previous.Range) = 1
  166.    oDoc.Paragraphs.Last.Previous.Range.Delete
  167.   Loop
  168.   Set oRng = oDoc.Paragraphs.Last.Range
  169.   With oRng
  170.    .Paragraphs(1).SpaceBefore = 0
  171.    .Paragraphs(1).SpaceAfter = 0
  172.    .Paragraphs(1).Range.Font.Size = 1
  173.   End With
  174. lbl_Exit:
  175.   System.Cursor = wdCursorNormal
  176.   Beep
  177.   With Application
  178.     .StatusBar = "Finished!!"
  179.     .ScreenUpdating = True
  180.     .ScreenRefresh
  181.   End With
  182.   Exit Sub
  183. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement