PDA

View Full Version : [SOLVED:] Set every line break on 8 points



gloub
12-08-2019, 10:40 AM
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 !

Mavila
12-08-2019, 08:17 PM
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?

gloub
12-09-2019, 12:11 AM
Yes !

gloub
12-15-2019, 04:23 AM
Hi
Any idea, anyone ?
Thanks.

gloub
12-28-2019, 02:14 PM
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

Bob Phillips
12-29-2019, 04:56 AM
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

Paul_Hossler
12-29-2019, 07:47 AM
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

25713

gloub
12-30-2019, 12:31 AM
Does this work?

Yes it does, thanks !!!

gloub
12-30-2019, 12:37 AM
Many thanks !


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.

gmayor
12-30-2019, 01:19 AM
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.

gloub
12-30-2019, 01:39 AM
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.