Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-13-2023, 01:34 PM
spillerbd spillerbd is offline Create Document using ALL Styles to demonstarte/document Windows 10 Create Document using ALL Styles to demonstarte/document Office 2021
Competent Performer
Create Document using ALL Styles to demonstarte/document
 
Join Date: Jan 2016
Posts: 130
spillerbd is on a distinguished road
Default Create Document using ALL Styles to demonstarte/document

Does anyone already have a VBA that will create or add to a document that not only list All Styles Available (Character, Paragraph and Linked) as well as a sample of the format?

This would help document the Styles in a Template or Document and give an opportunity to see the effects of changing any style or the cascade when style(s) are based on another.



For anyone willing to create one:
Sample Paragraph could be based on =RAND(2,5) or =LOREM(2,5)
Character text sample could just be like a font sample A-z and 0-9.
Reply With Quote
  #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,159
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
  #3  
Old 02-14-2023, 02:53 AM
Italophile Italophile is offline Create Document using ALL Styles to demonstarte/document Windows 11 Create Document using ALL Styles to demonstarte/document Office 2021
Expert
 
Join Date: Mar 2022
Posts: 539
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

If you want to see the effect of a table style's text formatting correctly, the paragraph to which the table is added must be formatted with the document defaults. The text formatting elements of a table style cannot overwrite character or paragraph styles.

Whilst the Normal style should be identical to the defaults in a newly created template that is not guaranteed if Normal has been modified.

This applies to all versions of Word since 2007.
Reply With Quote
  #4  
Old 02-25-2023, 09:08 AM
spillerbd spillerbd is offline Create Document using ALL Styles to demonstarte/document Windows 10 Create Document using ALL Styles to demonstarte/document Office 2021
Competent Performer
Create Document using ALL Styles to demonstarte/document
 
Join Date: Jan 2016
Posts: 130
spillerbd is on a distinguished road
Default

@ Andrew. Excellent and Thank you.
I am commenting the Table section out to just create/use all the Text Styles (character, paragraph and linked) in a document because of the quirks I've discovered working with Styles, Style Sets and Templates.

https://www.msofficeforums.com/word/...galleries.html
Reply With Quote
Reply

Tags
style list, template document styles, vba code



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 03:48 AM.


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