Assimilating non-heading numbering styles into in-house heading st

J

jerem

Am trying to find a clean and easy way to take foreign (non-heading styles)
numbering styles (those not used in my company) and convert them into
in-house (my company) heading styles.

For example: quite often we get documents from clients using let's say
L1 (instead of Heading 1), L2 (instead of Heading 2), etc. When using Find
and Replace, you can search out the L1 style (so my system can recognize the
style in the Find), however, it won't let me act on those styles cleanly -
that is, say now that you've found them replace them with Heading 1, Heading
2, etc. Sometimes in the Find/Replace what it will do is change all the
numbering to Normal style (or at least that's what appears in the 1 inch
style window to the left) yet you will see a numbering code when you graze
over the numbered portion of the text and it will read as a heading style,
however, the formatting is all screwy and the attributes to that style has
not been employed. Sometimes I can fix by hitting demote or promote, but
there is no consistency doing this. One big pain in the you know what.
Since this is so unreliable I end up having to manually go through the
document and apply the correct styles. (By the way, if there is no TOC being
generated from the document, I will leave the styles alone, but most often a
TOC is required).

I work in the legal arena and since we have the need to use a variety of
numbering schemes and multiple levels of numbering we've purchased a third
party software numbering package. Whether this has anything to do with it -
I don't know.

Seems to me, theoretically at least, that if you can recognize a style, you
can globally replace it neatly and cleanly. Anyone got any ideas?
Appreciate any help I can get.
 
S

Shauna Kelly

Hi

I think you did mean heading styles. For what it's worth, a header is
content that is repeated at the top of every page. And Word has a built-in
Header style that it uses by default for this purpose. A heading is a short
paragraph that announces the beginning of a portion of the text. Word has 9
built-in styles for this purpose: Heading 1, Heading 2, .... Heading 9.

So, as I understand it, you have a document with a style that is, say, L1.
And you want to search-and-replace it with style Heading 1. But when you do
that, the paragraphs don't display all the characteristics of Heading 1.

The likely cause is that the paragraphs are not only in style L1, they also
have direct formatting applied to them. You can test this out. To remove all
direct formatting, triple-click one of the L1 paragraphs to select it, and
then do ctrl-q and ctrl-spacebar. That removes all the paragraph-level and
font-level direct formatting. Did it change its look? If so, it had direct
formatting applied to it. Try this both before and after the
search-and-replace. Does that solve the problem?

If so, something like the following might help:

Option Explicit

Sub ReplaceL1WithHeading1()


Dim oDoc As Word.Document
Dim rng As Word.Range
Dim sStyleToFind As String
Dim sStyleToReplace As String


'Change these two lines to suit your needs
sStyleToFind = "L1"
sStyleToReplace = "Heading 1"


Set oDoc = ActiveDocument
Set rng = oDoc.Range.Duplicate

With rng.Find
.ClearAllFuzzyOptions
.ClearFormatting
.Replacement.ClearFormatting


.Text = ""
.Style = sStyleToFind
.Format = True
.Wrap = wdFindContinue
.Format = True
With .Replacement
.Text = ""
.Style = sStyleToReplace
End With


Do While .Execute(Replace:=wdReplaceOne)

'Reset the paragraph format
'(equivalent of ctrl-q)
rng.ParagraphFormat.Reset


'Reset the font format
'(equivalent of ctrl-spacebar)
rng.Font.Reset
Loop
End With

End Sub

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
J

jerem

Oops, meant heading styles - got it right in the subject matter, wrong in the
body of text. Is that like mixing metaphors???

I shall try this Monday and see if all goes well. I'm not sure if direct
formatting is the culprit since it seems that every heading level reacts the
same way to the global replacement and I can't imagine every paragraph in
that level being directly formatted since, generally speaking - I would
think, one would only directly format an individual heading level or an
isolated group of headings so that they maintain most of the heading
paragraph styling, but with something a little different about them specified
in the direct format (font setting, paragraph after, etc.).

I have one of those pain in the neck jobs sitting on my desk waiting for me.
I'll try your solution and let you know how it turned out. Thanks for your
quick reply.

jerem
 
S

Shauna Kelly

Hi

I hope it goes well.

I forgot to point out in my previous reply that the code will zap all direct
formatting, even direct formatting you might want to keep. So a heading "The
sinking of the _Titanic_" would lose its italics.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
J

jerem

Hi Shauna,

Did what you suggested - that is, I globally found each style, highlighted
all of them in the find then ctrlq(ed) and ctlspace(d) them and then globally
replaced them. That worked well. Apparently you were right about the direct
formatting. Other document I was working on must have had direct formatting
all over the place. Have not used the code yet since I wanted to see what
went on step by step first but will try that with my next problem job.
Thanks for your help.

By the way, I was looking for a book that addresses VBA in a Word
environment. The only one that I know of is Writing Word Macros by Steven
Roman, however, that book gets mixed reviews. I don't like buying books for
$35 and then finding out that it really wasn't that helpful. Are you
familiar with this book? I want something that covers the elemental but
moves into more intermediate and advanced topics - and something that is user
friendly. Any suggestions?
 

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