Visual Basic Macro question for Word --Parsing

D

dado_maker

Hi,
I would like to write a vis basic macro that will search the begining of
each line of my doc, that does not start with a space " " and change the
style of those lines.

I need to parse thru each line to search thru each string in my word
doc.

I didnt see a way using the macro recorder and believe I need to code
this if possible.
Any help would be appreciated!

Thanks,
Dado
 
J

Jonathan West

Hi dado

First and most important question - does each paragraph have just a single
line? In other words, can you iterate through paragraphs instead of through
lines?
 
G

Greg Maxey

dado_maker,

If each line is a indidual parapraph (i.e., no wrapped lines or line breaks)
then something like this may work for you:

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
 
D

dado_maker

Greg,

Sweet!
Thanks,
dado_maker

Greg said:
dado_maker,

If each line is a indidual parapraph (i.e., no wrapped lines or line breaks)
then something like this may work for you:

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
 
D

dado_maker

Greg,

Sweet!
Thanks,
dado_maker

Greg said:
dado_maker,

If each line is a indidual parapraph (i.e., no wrapped lines or line breaks)
then something like this may work for you:

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
 
D

dado_maker

Greg,

Sweet!

Thanks,
dado_maker



Greg said:
dado_maker,

If each line is a indidual parapraph (i.e., no wrapped lines or line breaks)
then something like this may work for you:

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top