![]() |
#1
|
|||
|
|||
![]()
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. |
#2
|
||||
|
||||
![]()
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 |
#3
|
|||
|
|||
![]()
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. |
#4
|
|||
|
|||
![]()
@ 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 |
![]() |
Tags |
style list, template document styles, vba code |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
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 |
![]() |
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 |