![]() |
|
#4
|
||||
|
||||
|
I assume that you mean you want a '+' sign in the space? That being the case you can adapt the previous macro e.g. as follows.
Code:
Sub Macro2()
'Graham Mayor - https://www.gmayor.com - Last updated - 20 Jan 2020
Dim i As Long
Dim oPara As Paragraph
Dim oRng As Range
'Create styles or use existing styles
On Error Resume Next
ActiveDocument.Styles.Add Name:="Body_Spaced", Type:=wdStyleTypeParagraph
ActiveDocument.Styles("Body_Spaced").AutomaticallyUpdate = False
With ActiveDocument.Styles("Body_Spaced").Font
.Name = "Calibri"
.Size = 12
End With
With ActiveDocument.Styles("Body_Spaced").ParagraphFormat
.SpaceAfter = 12
End With
ActiveDocument.Styles.Add Name:="Body_Unspaced", Type:= _
wdStyleTypeParagraph
ActiveDocument.Styles("Body_Unspaced").AutomaticallyUpdate = False
With ActiveDocument.Styles("Body_Unspaced").Font
.Name = "Calibri"
.Size = 12
End With
With ActiveDocument.Styles("Body_Unspaced").ParagraphFormat
.SpaceAfter = 0
End With
On Error GoTo 0
'end of style creation
'apply styles
For i = 1 To ActiveDocument.Paragraphs.Count
Set oPara = ActiveDocument.Paragraphs(i)
If i Mod 3 = 0 Then
oPara.Range.Style = "Body_Spaced"
Else
oPara.Range.Style = "Body_Unspaced"
End If
Next i
Set oRng = ActiveDocument.Range
With oRng.Find
.Style = "Body_Spaced"
Do While .Execute
If Len(oRng.Next.Paragraphs(1).Range) > 1 Then
oRng.InsertAfter "+" & vbCr
End If
oRng.Style = "Body_Unspaced"
oRng.Collapse 0
Loop
End With
Set oRng = Nothing
Set oPara = Nothing
End Sub
Code:
Sub Macro3()
'Graham Mayor - https://www.gmayor.com - Last updated - 20 Jan 2020
Dim oRng As Range
Dim lngPara As Long
Dim lngCount As Long
Const lngNum As Long = 3 'the number of paragraphs to group
lngCount = ActiveDocument.Paragraphs.Count
For lngPara = lngCount To 1 Step -1
'eliminate empty paragraphs at the end from the count
If Len(ActiveDocument.Paragraphs(lngPara).Range) = 1 Then
lngCount = lngCount - 1
Else
Exit For
End If
Next lngPara
'Find the end of the last of the grouped paragraphs
Do Until lngCount Mod lngNum = 0
lngCount = lngCount - 1
Loop
'Insert paragraphs containing a '+' character
For lngPara = lngCount To lngNum Step -lngNum
Set oRng = ActiveDocument.Paragraphs(lngPara).Range
oRng.InsertAfter "+" & vbCr
Next lngPara
Set oRng = Nothing
End Sub
Code:
oRng.InsertAfter "+" & vbCr
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com Last edited by gmayor; 01-20-2020 at 05:45 AM. |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
How to insert paragraph character after every 500 characters?
|
aditya_bokade | Word VBA | 28 | 11-13-2021 10:48 PM |
Word macro to insert text at the beginning of paragraph but skip tables
|
ashalles135 | Word VBA | 5 | 09-26-2018 09:49 AM |
word macro To insert text at the beginning and at end of paragraph
|
ArieH | Word VBA | 20 | 09-10-2017 04:23 PM |
Macro to Insert text into the beginning on specific paragraphs unless the paragraph is blank
|
caboy | Word VBA | 2 | 04-01-2015 07:00 AM |
Insert paragraph break before images
|
jsoule | Word VBA | 3 | 02-25-2015 07:53 AM |