0
votes

I am looking for a quick way to automate fixing headings in a Word document. I spent some time on Stackoverflow looking for a VB script and tried using the advanced find and replace features in Word.

The headers are up to 5 levels deep.

2.0 This should be Heading 1

2.1 This should be Heading 2

2.1.1 This should be Heading 3

2.1.1.1 This should be Heading 4

2.1.1.1.1 This should be Heading 5

There is a ton of text in between each heading.

The headings are typed rather than formatted using 'styles'.

All the headings are Times New Roman, Bold, 12pt.

I want to go through the document and repair all the headings with the proper level of heading style.

Seems easy enough. I did a find/replace based on the font; however I cannot distinguish between the different levels.

Any help would be greatly appreciated.

1

1 Answers

0
votes

It sounds like you need to do a Wildcard search. I'll preface this by saying Word's wildcard searching is not as sophisticated as other regular expression engines, and unless you are extremely confident that these heading strings are unique in the text, I'd run these by hand at least to start.


Search:
Font: Times New Roman Bold 12 pt
Wildcards on
[0-9]{1,}.[0-9]{1,}.[0-9]{1,}.[0-9]{1,}.[0-9]{1,}

Replace:
Style: Heading 5

Then
Search:
Font: Times New Roman Bold 12 pt
Wildcards on
[0-9]{1,}.[0-9]{1,}.[0-9]{1,}.[0-9]{1,}

Replace:
Style: Heading 4

Then
Search:
Font: Times New Roman Bold 12 pt
Wildcards on
[0-9]{1,}.[0-9]{1,}.[0-9]{1,}

Replace:
Style: Heading 3

Then
Search:
Font: Times New Roman Bold 12 pt
Wildcards on
[0-9]{1,}.[1-9]{1,}

Replace:
Style: Heading 2

Then
Search:
Font: Times New Roman Bold 12 pt
Wildcards on
[0-9]{1,}.0

Replace:
Style: Heading 1

I'd strongly recommend doing at least the last two searches by hand, as there may be other instances of bold text that matches those patterns within the text.

If you want a script, you can record this as a macro, but if there's just one document there's really no need.

This isn't really a coding question; not sure if should be moved to Super User.