none
set new style RRS feed

  • Question

  • I write: 

    Set NewStyle = ActiveDocument.Styles.Add(Name:=StyleName,  Type:=wdStyleTypeParagraph)

    what am I need write in type that the style define only this line, and when I break the line, I return to last style?

    Sunday, April 1, 2012 11:57 PM

Answers

  • "hila_d" wrote in message news:eb10125f-c6ee-477f-8e29-cf120414da53@communitybridge.codeplex.com...
    I have built in styles. I don't know how they are define.
     
    I want update "normal" style to be as I want.
     
    How am I update the built in style with macro?
     
     
    Generally, to modify the Normal style, you’d need code such as the following:
     
    Sub ModifyNormalStyle()
    Dim s As Style
     
    'Set a reference to the Normal style:
    Set s = ActiveDocument.Styles(wdStyleNormal)
     
    With s.Font
    'code that modifies font/character properties here
    End With
    With s.ParagraphFormat
    'code that modifies the paragraph properties here
    End With
     
    End Sub
     
    The details depend on which specific properties of the style that you want to modify.

    Stefan Blom, Microsoft Word MVP
    • Marked as answer by hila_d Monday, April 16, 2012 11:28 AM
    Sunday, April 15, 2012 9:32 PM

All replies

  • I write: 

    Set NewStyle = ActiveDocument.Styles.Add(Name:=StyleName,  Type:=wdStyleTypeParagraph)

    what am I need write in type that the style define only this line, and when I break the line, I return to last style?


    How am I check If style is exist? and no get error?
    Monday, April 2, 2012 4:21 PM
  • To see if a style already exists, you’ll have to loop through the Styles collection of the relevant file:
            
    Dim s As Style
    Dim t As Style
    For Each s In ActiveDocument.Styles
    If s.NameLocal = "Name of style you are testing for" Then
    Set t = s
    Exit For
    End If
    Next s
            
    'To set the style applied when you press Enter
    'use the NextParagraphStyle property:
    t.NextParagraphStyle = "Normal"
    'More code here

    Stefan Blom, Microsoft Word MVP
    Monday, April 2, 2012 6:51 PM
  • Can I create function that check - if style aleradt exists - update his defined, else set this style?

    how am I enter this to condition in loop?

    How am I can run this function when I open the word (new or old document?)?

    Tuesday, April 3, 2012 8:16 AM
  • You can use the t variable that I defined to make any changes that you want to the specified style.
     
    If you are saying that you want to replace a certain style with another one, Find and Replace will be helpful.

    Stefan Blom, Microsoft Word MVP
    Tuesday, April 3, 2012 11:54 PM
  • How can Iupdatean existingtextstyleis saved ina built-instyle?

    for examle- if I want update "normal" style, I get error 5173      

    Wednesday, April 4, 2012 12:22 PM
  • How can Iupdatean existingtextstyleis saved ina built-instyle?

    for examle- if I want update "normal" style, I get error 5173


          

    Please show us the code that triggers the error message.


    Stefan Blom, Microsoft Word MVP

    Wednesday, April 4, 2012 12:26 PM
  • Sub initStyle()
        Dim style As style
        Dim flagStyle As Boolean
        
        Dim arrStyle(4) As String
        arrStyle(0) = "normal"
        arrStyle(1) = "style 1"
        arrStyle(2) = "style 2"
        arrStyle(3) = "style 3"
    
        
        For i = 0 To 4
            flagStyle = False
           For Each style In ActiveDocument.Styles
        
               
               If style.NameLocal = arrStyle(i) Then
                   style.Delete
                    flagStyle = True
                    
                   Exit For
                            
               End If           
          Next style
    
        Set style = ActiveDocument.Styles.Add(Name:=arrStyle(i), Type:=wdStyleTypeParagraph)
    
          
        Next i
        
    End Sub

    I get an error on line: "set Style = ...)
    • Edited by hila_d Wednesday, April 4, 2012 12:54 PM
    Wednesday, April 4, 2012 12:53 PM
  • You can’t delete a built-in style; nor can you create a custom style that has the same name as a built-in style. Instead, you will have to modify it to suit your needs.

    Stefan Blom, Microsoft Word MVP
    Thursday, April 5, 2012 6:20 PM
  • How can I define the buile-in style through macro?
    Sunday, April 15, 2012 8:57 AM
  • "hila_d" wrote in message news:7a652cc3-1378-48bb-95c8-50fe5b750a20@communitybridge.codeplex.com...
    How can I define the buile-in style through macro?
     
     
    What are the specific modifications that you want to do?

    Stefan Blom, Microsoft Word MVP
    Sunday, April 15, 2012 7:13 PM
  • I have built in styles. I don't know how they are define.

    I want update "normal" style to be as I want.

    How am I update the built in style with macro? 

    Sunday, April 15, 2012 9:14 PM
  • "hila_d" wrote in message news:eb10125f-c6ee-477f-8e29-cf120414da53@communitybridge.codeplex.com...
    I have built in styles. I don't know how they are define.
     
    I want update "normal" style to be as I want.
     
    How am I update the built in style with macro?
     
     
    Generally, to modify the Normal style, you’d need code such as the following:
     
    Sub ModifyNormalStyle()
    Dim s As Style
     
    'Set a reference to the Normal style:
    Set s = ActiveDocument.Styles(wdStyleNormal)
     
    With s.Font
    'code that modifies font/character properties here
    End With
    With s.ParagraphFormat
    'code that modifies the paragraph properties here
    End With
     
    End Sub
     
    The details depend on which specific properties of the style that you want to modify.

    Stefan Blom, Microsoft Word MVP
    • Marked as answer by hila_d Monday, April 16, 2012 11:28 AM
    Sunday, April 15, 2012 9:32 PM
  • thank you
    Monday, April 16, 2012 11:28 AM
  • I have another question -

    what am I need to write in macro to set the fonts in Quick-style-list?


    How am I order the style in gallery (that normal will be first)?
    • Edited by hila_d Thursday, April 19, 2012 8:14 AM
    Thursday, April 19, 2012 7:07 AM
  • "hila_d" wrote in message news:43fecb6e-87f2-417c-ba1c-270a0963ae6c@communitybridge.codeplex.com...
    I have another question -
     
    what am I need to write in macro to set the fonts in Quick-style-list?
     
    How am I order the style in gallery (that normal will be first)?
     
     
     
    The styles in the gallery can be modified as any other styles, but you’d have to recreate the style set to replace the existing one.
     
    The order of the styles in the gallery depends on the priority value specified (on the Recommend tab of the Manage Styles dialog box) for each style (that belongs to the style set).
     
    You should repost this as a new question in a new thread; that way, it will get the full attention of everyone who participates in this forum.

    Stefan Blom, Microsoft Word MVP
    Thursday, April 19, 2012 9:23 PM