View Single Post
 
Old 02-13-2023, 04:07 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Here's one I prepared earlier...
Code:
Sub InsertAllStyleSamples()
'Inserts samples of all present style entries into the current file
  Dim sStyle As Style, sText As String, oTbl As Table
  Dim rngChars As Range, rngParas As Range, rngTables As Range, rngLists As Range
  sText = " - The quick brown fox jumped over the lazy dog. " & _
      "12345 67890 The quick brown fox jumped over the lazy dog."
      
  For Each sStyle In ActiveDocument.Styles
    'If sStyle.Locked = False Then
    'If sStyle.Priority > 4 And sStyle.Priority < 50 Then
      Select Case sStyle.Type
        Case wdStyleTypeCharacter
          Selection.Style = "Normal"      'the base paragraph style
          Selection.Style = sStyle        'the character style
          Selection.TypeText sStyle & " - character style" & vbCr
          Selection.Font.Reset
        Case wdStyleTypeList
          'do nothing
        Case wdStyleTypeParagraph
          Selection.Style = sStyle        'the style
          Selection.TypeText sStyle & sText & vbCr
        
        Case wdStyleTypeTable
          If sStyle.Visibility = False Then       'only if style is visible
            Set oTbl = ActiveDocument.Tables.Add(Selection.Range, 3, 3)
            With oTbl
              oTbl.Style = sStyle   'the table style
              oTbl.Range.Style = "Table Text"   'the paragraph style (will fail if style doesn't exist)
              oTbl.Rows(1).Range.Style = "Table Heading"
              oTbl.cell(1, 1).Range.Text = sStyle & " - Table Style"
              oTbl.cell(2, 1).Range.Text = "Table Text Paragraph Style"
              oTbl.cell(3, 1).Range.Text = Mid(sText, 4, 15)
              oTbl.cell(1, 2).Range.Text = "Table Heading Paragraph Style"
              oTbl.cell(2, 2).Range.Text = Mid(sText, 4, 15)
              oTbl.cell(3, 2).Range.Text = Mid(sText, 4, 15)
              oTbl.cell(1, 3).Range.Text = Mid(sText, 4, 15)
              oTbl.cell(2, 3).Range.Text = Mid(sText, 4, 15)
              oTbl.cell(3, 3).Range.Text = Mid(sText, 4, 15)
            End With
            oTbl.Range.Select
            Selection.MoveDown
            Selection.TypeText vbCr
          End If
          'do nothing
      End Select
    'End If
  Next sStyle
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote