Macro to select all continuous text of a particular

  • Thread starter susiecc via OfficeKB.com
  • Start date
S

susiecc via OfficeKB.com

I'm trying to create a simple macro that will select all continuous lines of
a particular style. So, for example, I have 20 lines of normal, then 2 lines
of Heading, then 20 more lines of normal.

I want to be able to select that first 20 lines of normal, do an operation on
it, then move to the next 20 lines of normal, do an operation on it, etc...
until I cycle through the document and change certain features of each of
those style blocks.

Is there an easy way to simply select each complete chunk of a style, even
thos it contain several paragraphs?

thanks, sue
 
K

Klaus Linke

susiecc via OfficeKB.com said:
I'm trying to create a simple macro that will select all continuous lines
of
a particular style. So, for example, I have 20 lines of normal, then 2
lines
of Heading, then 20 more lines of normal.

I want to be able to select that first 20 lines of normal, do an operation
on
it, then move to the next 20 lines of normal, do an operation on it,
etc...
until I cycle through the document and change certain features of each of
those style blocks.

Is there an easy way to simply select each complete chunk of a style, even
thos it contain several paragraphs?


Hi Sue,

Not really. It can be done, but it would be pretty cumbersome, and slow on
long documents.
Can you give examples of what you want to do to those chunks of text,
depending on their paragraph style?

If you use Find/Replace and search for some style, and use "Replace all",
Word will match each of the chunks you're looking for just once (even if it
has lots of paragraphs). Maybe that might lead to some good, fast
approach...

Or you might loop through the paragraphs collection, noticing where the
style changes. That would be slower, but probably still acceptable, and easy
to write.

Regards,
Klaus
 
S

susiecc via OfficeKB.com

Hi.
I want to select all contiguous text that is of normal style, make the first
paragraph a different style, make the last paragraph a different style and
make the rest of the text a different style. so, i would have first line as
BM, text until the end as BM_Md, and last paragraph as BM_Ls.

Then, I want to go to the next contiguous block of normal text and do the
same thing. I want to continue doing this until all the contiquous normal
text is styled the same, with the 3 different styles.

sue

Klaus said:
I'm trying to create a simple macro that will select all continuous lines
of
[quoted text clipped - 11 lines]
Is there an easy way to simply select each complete chunk of a style, even
thos it contain several paragraphs?

Hi Sue,

Not really. It can be done, but it would be pretty cumbersome, and slow on
long documents.
Can you give examples of what you want to do to those chunks of text,
depending on their paragraph style?

If you use Find/Replace and search for some style, and use "Replace all",
Word will match each of the chunks you're looking for just once (even if it
has lots of paragraphs). Maybe that might lead to some good, fast
approach...

Or you might loop through the paragraphs collection, noticing where the
style changes. That would be slower, but probably still acceptable, and easy
to write.

Regards,
Klaus
 
K

Klaus Linke

I often put in temporary tags:
Search for Normal style (leave "Find what" empty, or use .Text="" in the
macro).
Replace with "<S>^&</S>", Replace All.

Then replace ^p</S> with </S>^p

Now it should be easy to apply your three new styles with more Find/Replace,
and finally delete the tags with still more.

Or maybe easier to write/read -- Loop all paragraphs:

Dim myPara as Paragraph
Dim boolStandardRun as Boolean
For each myPara in ActiveDocument.Paragraphs
If myPara.Style=ActiveDocument.Styles(wdStyleNormal) Then
If boolStandardRun=False then
' apply style for first para in run
boolStandardRun=True
Else
' apply style for middle paras in run
Endif
Else
' apply style for end para to myPara.Previous
boolStandardRun=False
Endif
Next myPara


Regards,
Klaus


susiecc via OfficeKB.com said:
Hi.
I want to select all contiguous text that is of normal style, make the
first
paragraph a different style, make the last paragraph a different style and
make the rest of the text a different style. so, i would have first line
as
BM, text until the end as BM_Md, and last paragraph as BM_Ls.

Then, I want to go to the next contiguous block of normal text and do the
same thing. I want to continue doing this until all the contiquous normal
text is styled the same, with the 3 different styles.

sue

Klaus said:
I'm trying to create a simple macro that will select all continuous
lines
of
[quoted text clipped - 11 lines]
Is there an easy way to simply select each complete chunk of a style,
even
thos it contain several paragraphs?

Hi Sue,

Not really. It can be done, but it would be pretty cumbersome, and slow on
long documents.
Can you give examples of what you want to do to those chunks of text,
depending on their paragraph style?

If you use Find/Replace and search for some style, and use "Replace all",
Word will match each of the chunks you're looking for just once (even if
it
has lots of paragraphs). Maybe that might lead to some good, fast
approach...

Or you might loop through the paragraphs collection, noticing where the
style changes. That would be slower, but probably still acceptable, and
easy
to write.

Regards,
Klaus
 
K

Klaus Linke

Hi Sue,

BTW, if your only reason for using these three styles is to influence the
spacing between paragraphs, there are probably better ways that use only one
style.
You could suppress the spacing between paragraphs of the same style
(checkbox in Format > Paragraph), and if you do want *some* spacing anyway,
you could achieve it with a white paragraph border.

Using three styles can be a maintenance nightmare down the road.

Regards,
Klaus
 
S

susiecc via OfficeKB.com

Hi Klaus,

We do publishing in our company. All Word documents are flowed into another
program (QuarkXPress). The designers have preconfigured styles that are
applied to the text. By creating beginning, middle, and end styles using
those preconfigured style names, the designers have less hand work to do when
they bring a Word document into their desktop publishing software. Usually,
as I said, that's QuarkXpress, but sometimes, it's also Indesign. Setting up
first, middle and last styles makes paging books so much faster.

I'll try your macro and let you know how it goes.

Thanks so much,

sue
 

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