Consulting

Results 1 to 11 of 11

Thread: Set every line break on 8 points

  1. #1
    VBAX Regular
    Joined
    Dec 2019
    Posts
    14
    Location

    Set every line break on 8 points

    Hi !

    I'm trying to write a macro that would set every line break on 8 points, but the macro recorder keeps no trace of the font size :
    Sub Format_Line_breaks_8_pts()'
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find
            .Text = "^p"
            .Replacement.Text = "^p"
            .Forward = True
            .Format = True
            .MatchWildcards = False
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
    End Sub
    Could anyone help me make it work ?
    Many thanks !

  2. #2
    VBAX Contributor
    Joined
    Aug 2012
    Posts
    120
    Location
    Not sure what you mean by, "set every line break on 8 points."

    If you mean size the line break to 8, then:

    Selection.Paragraphs(1).Range.Font.Size = 8

    might work?

  3. #3
    VBAX Regular
    Joined
    Dec 2019
    Posts
    14
    Location
    Yes !

  4. #4
    VBAX Regular
    Joined
    Dec 2019
    Posts
    14
    Location
    Hi
    Any idea, anyone ?
    Thanks.

  5. #5
    VBAX Regular
    Joined
    Dec 2019
    Posts
    14
    Location
    So, here is the maximum I can do, deriving from existing code :
    Sub xmacrolignes()Dim Para As Paragraph
    For Each Para In ActiveDocument.Paragraphs
    
    
    With Selection.Find
            .Execute FindText:="^p"
    End With
    
    
    With Selection.Font
            Size = 8
    End With
    
    
    Next Para
    ...unfortunately, it doesn't set every line break to 8 points :^(

    Any idea as to what I should change to make this macro work ?

    Thanks

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,443
    Location
    Does this work?

    Sub xmacrolignes()Dim Para As Paragraph
    
        For Each Para In ActiveDocument.Paragraphs
    
            With Selection
    
                .Find.Execute FindText:="^p"
                .Font.Size = 8
            End With
        Next Para
    End Sub
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Quote Originally Posted by gloub View Post
    Hi !

    I'm trying to write a macro that would set every line break on 8 points, but the macro recorder keeps no trace of the font size :
    Could anyone help me make it work ?
    Many thanks !

    I'd use Styles for formatting like this, but to answer the question



    Option Explicit
    
    
    Sub Macro1()
    '
    ' Macro1 Macro
    '
    '
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        Selection.Find.Replacement.Font.Size = 8    '   <<<<<<<<<<<<<<<<<<<<
        With Selection.Find
            .Text = "^p"
            .Replacement.Text = "^p"
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
    End Sub

    In the F&R dialog, put your cursor in Replace With and click Formatting and select Font

    Capture.JPG
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  8. #8
    VBAX Regular
    Joined
    Dec 2019
    Posts
    14
    Location
    Quote Originally Posted by xld View Post
    Does this work?
    Yes it does, thanks !!!

  9. #9
    VBAX Regular
    Joined
    Dec 2019
    Posts
    14
    Location
    Many thanks !

    Quote Originally Posted by Paul_Hossler View Post
    I'd use Styles for formatting like this
    For several reasons not worth explaining here, I prefer not to use styles.

    Thanks for your code, it works perfectly (and, as the file I'm working on is quite long – about 40 pages – it's faster than what "xld" submitted, but xld didn't have the whole context).

    In the F&R dialog, put your cursor in Replace With and click Formatting and select Font
    As I'm mainly working with Word 2003, this option is not available.

    Thanks again.

  10. #10
    Quote Originally Posted by gloub View Post
    As I'm mainly working with Word 2003, this option is not available.
    It is available in 2003 (and earlier) click the 'More' button in the Replace dialog.

    You cannot avoid using styles in Word as it is a style driven program, so it is always better to use them properly than to try and work around them. Yes you can employ manual formatting, but then it makes editing more complex than it needs to be and results in the type of problem that gave rise to your initial question.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  11. #11
    VBAX Regular
    Joined
    Dec 2019
    Posts
    14
    Location
    Thanks for this quick answer that helps me go even further than whan I expected.

    It is available in 2003 (and earlier) click the 'More' button in the Replace dialog.
    Oooops... You're right. I had checked in the wrong dialog... :^D

    You cannot avoid using styles in Word (...) so it is always better to use them properly than to try and work around them
    I know this, and I use them extensively. But the file I needed help for is something wild ;^)
    Thanks for the advice anyway.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •