dj44
10-05-2017, 02:09 PM
Add Number of Times - Loop Array
folks good day,
and nice to see all.
I had a idea to space out some text so i wanted to say insert new lines to space out the blocks so i can see them better
Sub Space_Out_Text()
Dim oRng As Word.Range
Dim oTargetParagraphs As Variant
Dim xAfterText As Variant
Dim i As Long, j As Long
Dim oPara As Word.Paragraph
oTargetParagraphs = Array("#MX18", "#JK78") '
xBeforeText = Array(vbNewLine & vbNewLine, vbNewLine & vbNewLine) ' Insert Before
xAfterText = Array(vbNewLine & vbNewLine&vbNewline, vbNewLine & vbNewLine) ' Insert After
For i = 0 To UBound(oTargetParagraphs)
Set oRng = ActiveDocument.Range
j = 0
With oRng.Find
Do While .Execute(FindText:=oTargetParagraphs(i), MatchWholeWord:=True)
If .Found Then
oRng.Expand Unit:=wdParagraph
oRng.Words.First.InsertBefore xBeforeText(i)
oRng.Words.Last.InsertBefore xAfterText(i)
End If
oRng.Collapse 0
Loop
End With
Next i
Set oRng = Nothing
End Sub
now if for example i wanted 10 vb lines for an array term, i would hate to have to do this
vbNewLine & vbNewLine &vbNewLine & vbNewLine& vbNewLine & vbNewLine in the array for one target paragraph
that looks very unelegant
is there a better way for me to insert a number of vblines without having to repeat them in the array?
Is there a more efficient way for me to say I want 10 vblines inserted , another term in the array i may want 5 vblines
well its very confusing to explain but i hope i made sense
and thank you
folks good day,
and nice to see all.
I had a idea to space out some text so i wanted to say insert new lines to space out the blocks so i can see them better
Sub Space_Out_Text()
Dim oRng As Word.Range
Dim oTargetParagraphs As Variant
Dim xAfterText As Variant
Dim i As Long, j As Long
Dim oPara As Word.Paragraph
oTargetParagraphs = Array("#MX18", "#JK78") '
xBeforeText = Array(vbNewLine & vbNewLine, vbNewLine & vbNewLine) ' Insert Before
xAfterText = Array(vbNewLine & vbNewLine&vbNewline, vbNewLine & vbNewLine) ' Insert After
For i = 0 To UBound(oTargetParagraphs)
Set oRng = ActiveDocument.Range
j = 0
With oRng.Find
Do While .Execute(FindText:=oTargetParagraphs(i), MatchWholeWord:=True)
If .Found Then
oRng.Expand Unit:=wdParagraph
oRng.Words.First.InsertBefore xBeforeText(i)
oRng.Words.Last.InsertBefore xAfterText(i)
End If
oRng.Collapse 0
Loop
End With
Next i
Set oRng = Nothing
End Sub
now if for example i wanted 10 vb lines for an array term, i would hate to have to do this
vbNewLine & vbNewLine &vbNewLine & vbNewLine& vbNewLine & vbNewLine in the array for one target paragraph
that looks very unelegant
is there a better way for me to insert a number of vblines without having to repeat them in the array?
Is there a more efficient way for me to say I want 10 vblines inserted , another term in the array i may want 5 vblines
well its very confusing to explain but i hope i made sense
and thank you