G
Greg Maxey
Masters,
Earlier today I helped and OP looking for a way to look at each line in the
document and "If" the first character was not a space to assign a different
style. This is what I proposed:
Sub ScratchMacro()
Dim oPar As Paragraph
Dim myRange As Range
For Each oPar In ActiveDocument.Paragraphs
Set myRange = oPar.Range
If Not myRange.Characters.First = " " Then
oPar.Style = "Body Text"
End If
Next
End Sub
I continued playing with this question and came up with this:
Sub Test()
Dim oPar As Paragraph
Dim myString As String
For Each oPar In ActiveDocument.Paragraphs
myString = oPar.Range.Text
If Not Left(myString, 1) = " " Then
oPar.Style = "Body Text"
End If
Next
End Sub
Both seem to work equally well on the limited sample text that I tested
with. My question is which, if either, is the more appropriate and why?
Thanks.
Earlier today I helped and OP looking for a way to look at each line in the
document and "If" the first character was not a space to assign a different
style. This is what I proposed:
Sub ScratchMacro()
Dim oPar As Paragraph
Dim myRange As Range
For Each oPar In ActiveDocument.Paragraphs
Set myRange = oPar.Range
If Not myRange.Characters.First = " " Then
oPar.Style = "Body Text"
End If
Next
End Sub
I continued playing with this question and came up with this:
Sub Test()
Dim oPar As Paragraph
Dim myString As String
For Each oPar In ActiveDocument.Paragraphs
myString = oPar.Range.Text
If Not Left(myString, 1) = " " Then
oPar.Style = "Body Text"
End If
Next
End Sub
Both seem to work equally well on the limited sample text that I tested
with. My question is which, if either, is the more appropriate and why?
Thanks.