Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 02-13-2023, 04:07 PM
Guessed's Avatar
Guessed Guessed is offline Create Document using ALL Styles to demonstarte/document Windows 10 Create Document using ALL Styles to demonstarte/document Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,185
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
 

Tags
style list, template document styles, vba code

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create Document using ALL Styles to demonstarte/document Find several words in document, copy paragraph and create new document coolio2341 Word VBA 6 01-31-2019 01:17 PM
Does a new set of styles in a template overwrite or remove the existing set of styles in a document? dianahbr Word 6 03-27-2018 11:12 PM
Single step Word Styles from Source Document through entire Destination document? xbliss Word 6 08-27-2016 09:36 PM
Create Document using ALL Styles to demonstarte/document Word 2010 - How to create a fillable document from a boilerplate document sheaters Word 2 05-04-2016 01:57 PM
document styles and some formatting doesn't appear where should when different people view document Dilbert fan Word 1 08-23-2015 05:07 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:46 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft