Skip to main content
Inspiring
May 8, 2018
Answered

Apply new style to following paragraph throughout document

  • May 8, 2018
  • 2 replies
  • 687 views

Hi all

Hopefully this is simple!…

I have document with a tonne of Heading 3 styles and I need to ensure that the first following paragraph - and only that first paragraph -  gets converted to a separately created untabbed body paragraph style.

How do I issue a search and replace command to achieve that?

NB: there are over 700 of these Heading 3 + first following paragraph instances.

Many thanks in advance for any guidance 🙂

VBW

M

This topic has been closed for replies.
Correct answer FRIdNGE

A very short way! …

var myParas = app.activeDocument.stories.everyItem().paragraphs.everyItem().getElements(),

P = myParas.length,  p,

myPStylesList = ["Blue", "Red"]; // Names of the 2 Para Styles to be played!

for ( p = 0; p < P; p++ ) if ( myParas

.appliedParagraphStyle.name == myPStylesList[0] ) myParas[p+1].appliedParagraphStyle = myPStylesList[1]; 

Best,

Michel, from FRIdNGE

2 replies

FRIdNGE
FRIdNGECorrect answer
May 8, 2018

A very short way! …

var myParas = app.activeDocument.stories.everyItem().paragraphs.everyItem().getElements(),

P = myParas.length,  p,

myPStylesList = ["Blue", "Red"]; // Names of the 2 Para Styles to be played!

for ( p = 0; p < P; p++ ) if ( myParas

.appliedParagraphStyle.name == myPStylesList[0] ) myParas[p+1].appliedParagraphStyle = myPStylesList[1]; 

Best,

Michel, from FRIdNGE

Inspiring
May 9, 2018

Hi Michel

That worked brilliantly. Thank you so much!

The final script was:

var myParas = app.activeDocument.stories.everyItem().paragraphs.everyItem().getElements(), 

P = myParas.length,  p, 

myPStylesList = ["Heading 3", "Untabbed"]; 

for ( p = 0; p < P; p++ ) if ( myParas

.appliedParagraphStyle.name == myPStylesList[0] ) myParas[p+1].appliedParagraphStyle = myPStylesList[1];

Very best wishes to both you and Michael for the replies

Mark

Mike Witherell
Community Expert
Community Expert
May 8, 2018

It is probably too late to edit your Head style and setup the Next Style as Body.

Try a script from Stephan Moebius

HilfDirSelbst

Mike Witherell