|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Need to do this for more than 20 styles is any option is there. help me on this
Sub test_style_exists()
Dim test_style As String On Error Resume Next test_style = "Quota" MsgBox "Style " & test_style & " exists in " & ActiveDocument.Name & "?" & vbCr & _ style_exists(ActiveDocument, test_style) If Not MyStyle Is Nothing Then Set MyStyle = Application.ActiveDocument.Styles.Add(test_style, wdStyleTypeParagraph) End If End Sub Function style_exists(test_document As Word.Document, style_name As String) As Boolean style_exists = False On Error Resume Next style_exists = test_document.Styles(style_name).NameLocal = style_name End Function |
#2
|
||||
|
||||
How about. Change the style names as required
Code:
Option Explicit Sub AddStylesFromList() Dim MyStyle As Style Dim bExists As Boolean Dim i As Integer Dim vStyle(19) As Variant vStyle(0) = "Stylename1" vStyle(1) = "Stylename2" vStyle(2) = "Stylename3" vStyle(3) = "Stylename4" vStyle(4) = "Stylename5" vStyle(5) = "Stylename6" vStyle(6) = "Stylename7" vStyle(7) = "Stylename8" vStyle(8) = "Stylename9" vStyle(9) = "Stylename10" vStyle(10) = "Stylename11" vStyle(11) = "Stylename12" vStyle(12) = "Stylename13" vStyle(13) = "Stylename14" vStyle(14) = "Stylename15" vStyle(15) = "Stylename16" vStyle(16) = "Stylename17" vStyle(17) = "Stylename18" vStyle(18) = "Stylename19" vStyle(19) = "Stylename20" On Error Resume Next For i = 0 To 19 bExists = style_exists(ActiveDocument, CStr(vStyle(i))) If bExists = False Then Application.ActiveDocument.Styles.Add CStr(vStyle(i)), wdStyleTypeParagraph DoEvents Next i End Sub Function style_exists(test_document As Word.Document, style_name As String) As Boolean style_exists = False On Error Resume Next style_exists = test_document.Styles(style_name).NameLocal = style_name End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
can we add
can we add font name in that.
(e.g.) Times New Roman, Calibri if we create same as for characters style can we add the attributes in that (e.g.) bold, italic, superscript, subscript. |
#4
|
||||
|
||||
You can include any style parameters e.g. as follows
Code:
Option Explicit Sub AddStylesFromList() Dim MyStyle As Style Dim bExists As Boolean Dim i As Integer Dim vStyle(19) As Variant vStyle(0) = "Stylename1" vStyle(1) = "Stylename2" vStyle(2) = "Stylename3" vStyle(3) = "Stylename4" vStyle(4) = "Stylename5" vStyle(5) = "Stylename6" vStyle(6) = "Stylename7" vStyle(7) = "Stylename8" vStyle(8) = "Stylename9" vStyle(9) = "Stylename10" vStyle(10) = "Stylename11" vStyle(11) = "Stylename12" vStyle(12) = "Stylename13" vStyle(13) = "Stylename14" vStyle(14) = "Stylename15" vStyle(15) = "Stylename16" vStyle(16) = "Stylename17" vStyle(17) = "Stylename18" vStyle(18) = "Stylename19" vStyle(19) = "Stylename20" On Error Resume Next For i = 0 To 19 bExists = style_exists(ActiveDocument, CStr(vStyle(i))) If bExists = False Then Set MyStyle = Application.ActiveDocument.Styles.Add(CStr(vStyle(i)), wdStyleTypeParagraph) With MyStyle Select Case i Case 0 .Font.Name = "Calibri" .Font.Size = 12 Case 1 .Font.Name = "Times New Roman" .Font.Bold = True .Font.Size = 16 Case 2 .Font.Name = "Times New Roman" .Font.Italic = True .Font.Size = 14 Case 3 .Font.Name = "Times New Roman" .Font.Superscript = True .Font.Size = 12 'etc End Select End With End If DoEvents Next i End Sub Function style_exists(test_document As Word.Document, style_name As String) As Boolean style_exists = False On Error Resume Next style_exists = test_document.Styles(style_name).NameLocal = style_name End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#5
|
|||
|
|||
Thanks, one more think
while i find and replace its only finding and replace in document body, I need to find the in footnote and endnote too.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Creating buttons for individual paragraph styles on a ribbon tab - not using Quick Styles | T7Training | Word | 11 | 12-22-2019 12:16 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 |
Two much blank space between names of styles in the Styles Pane | PereCasanellas | Word | 0 | 10-06-2017 03:47 AM |
Question about spacing between multi-level bullet styles (and other styles) | SDwriter | Word | 0 | 09-26-2017 09:39 AM |
Styles: Only this document option | jthomas666 | Word | 1 | 06-27-2016 12:35 PM |