PDA

View Full Version : [SOLVED:] Change "old" styles to "new styles", new vs old style names similar but not exact



lkpederson
02-03-2015, 11:33 AM
All,
Often I get documents that contain previous versions of styles. The style names have changed only. The good news is that there are similarities between the old and new names. I've tried using a wildcard search for styles but no joy. I've also tried using "like" and no joy.

Here are some of the new style names:
_01_CSI SECTION
PART 1 _02_CSI PART
1.01 _03_CSI ARTICLE

Old style names
CSI SECTION or 01 CSI SECTION
CSI PART or 02 CSI PART

There are enough similarities to be able to do a wildcard search.

That's the first part.

Additionally, some of these same files have extraneous character formatting in a paragraph. The sentence or paragraph needs to be one style.

Example
CSI SECTION + 11 pt font, black <-- old format plus extraneous character format. Can also have condensed text.

What it should be:
_01_ CSI SECTION <-- new format

Ideas?

TIA

gmayor
02-04-2015, 12:38 AM
Without having the document available to test, maybe soimething like:



Sub ReplaceStyles()
Dim oPara As Paragraph
For Each oPara In ActiveDocument.Range.Paragraphs
If oPara.Style Like "CSI SECTION*" Then
oPara.Style = "_01_CSI SECTION"
oPara.Range.ParagraphFormat.Reset
oPara.Range.Font.Reset
End If
If oPara.Style Like "01 CSI SECTION*" Then
oPara.Style = "_01_CSI SECTION"
oPara.Range.ParagraphFormat.Reset
oPara.Range.Font.Reset
End If
If oPara.Style Like "CSI PART*" Then
oPara.Style = "PART 1 _02_CSI PART"
oPara.Range.ParagraphFormat.Reset
oPara.Range.Font.Reset
End If
If oPara.Style Like "02 CSI PART*" Then
oPara.Style = "PART 1 _02_CSI PART"
oPara.Range.ParagraphFormat.Reset
oPara.Range.Font.Reset
End If
Next oPara
lbl_Exit:
Exit Sub
End Sub

lkpederson
02-04-2015, 06:59 AM
Graham,
That worked a treat! Thanks. Had the syntax wrong (obviously) for the LIKE.

/r
Lise