PDA

View Full Version : how to multiply paragraphs



mateja
08-02-2010, 10:00 AM
I wish to multiply (by 2) all paragraps that are above 12pt

so text like
xxxxxx xxxxx paragraph (16pt)
xxxx xxxxxxx paragrapg (16pt)

will look like
xxxxxx xxxxx paragraph
paragraph
xxxx xxxxxxx paragrapg
paragrapg

gmaxey
08-03-2010, 01:10 PM
Are you sure you really want to do that? Or do you just want to have additional space after those paragraphs. Consider:

Sub ScratchMaco()
Dim oPar As Paragraph
For Each oPar In ActiveDocument.Paragraphs
If oPar.Range.Font.Size > 16 Then
oPar.SpaceAfter = oPar.Range.Font.Size
End If
Next
End Sub

fumei
08-03-2010, 02:08 PM
Cute Greg, using the value of the font.size as the space after. Cute.

mateja, I would strongly recommend you learn about using Styles fully. Word is totally designed around Styles, and using them properly gives full control over format - including spaces between paragraphs.

gmaxey
08-03-2010, 03:59 PM
Being cute was not the objective ;-). I just wanted to throw out anything to avoid the nightmare of multiply paragraphs.

mateja,

Gerry is right and there is no offense intended in the statement above. Reasons to avoid attempts to multiply paragraphs is that empty paragraphs in general should be avoided and if you are not very careful then attempts to do it with code could lead to empty paragraphs breeding like rabbits.

Perphaps you already have a large document with various large fonts applied and you want to create styles to adjust spacing (or any paragraph attribute).

You could run the following macro to create the basis styles from what you already have. Then just rename the styles to something that makes more sense for you:

Sub ScratchMacro()
Dim oPar As Paragraph
Dim oStyle As Style
For Each oPar In ActiveDocument.Paragraphs
If oPar.Range.Font.Size > 16 Then
On Error Resume Next
Set oStyle = ActiveDocument.Styles("BigFont " & oPar.Range.Font.Size)
Select Case Err.Number
Case 0
oPar.Style = oStyle
Case Else
oPar.Range.Select
Set oStyle = ActiveDocument.Styles.Add("BigFont " & oPar.Range.Font.Size, wdStyleTypeParagraph)
oStyle.ParagraphFormat.SpaceAfter = oPar.Range.Font.Size
oPar.Style = oStyle
End Select
End If
Next
End Sub

fumei
08-03-2010, 04:06 PM
Oh but that is what makes it cute, the fact you were not trying to be cute. It is cute in the sense of an elegant and correct reply that specifically answers the question in a literal way, yet still not precisely the way it was asked.

You did not "multiply"; you made the effect of "multiplication" without any real multiplication...ergo...cute.

Worse yet, your basis style procedure is...even CUTER.

Ta-ta. Adios. I am finally heading out of the office, and out into the wilderness.

"See" you all in September.

mateja
08-05-2010, 05:00 AM
Cute Greg, using the value of the font.size as the space after. Cute.

mateja, I would strongly recommend you learn about using Styles fully. Word is totally designed around Styles, and using them properly gives full control over format - including spaces between paragraphs.

The thing is that I am adding word text (converted from pdf) to text editor od TYPO3. Problem is that paragraphs are allways shown as 0pt, so there is no aditional space between paragraphs.
If word text looks like this:
xxxxxx xxxxx xxxx xxx
xxx xxxxx xxxxx xxxxx

xxxxx xxx xxx xxxxxxx

text shown on the web page looks like this
xxxxxx xxxxx xxxx xxx
xxx xxxxx xxxxx xxxxx
xxxxx xxx xxx xxxxxxx

So tell me if there is any other solution, since our web site hosting / development company told me that typo3 can't be adoptet to show the styles from word correctly.

gmaxey
08-05-2010, 01:50 PM
Ok. I don't understand your problem but this does literally what you originally asked:

Public Sub MultiplyParagraphs()
Dim oPar As Range
With ActiveDocument.StoryRanges(wdMainTextStory)
Set oPar = .Paragraphs(1).Range
Do
If oPar.Font.Size > 16 Then
oPar.InsertAfter vbCr
oPar.Characters.Last.Font.Size = oPar.Font.Size
End If
oPar.Collapse wdCollapseEnd
oPar.MoveEnd wdParagraph, 1
Loop Until oPar.End = .End
End With
Set oPar = Nothing
End Sub