Macro to format

M

mmikedm1000

I have two questions concerning using a macro to do some style changes.

First I need a macro to change some Heading 2s that are indented. The macro
will need to determine if the Heading 2 is indented and if it is outdent.

Second I need a macro that will look through a document and when it finds
"See also" it deletes that and everything after that for one page. These are
word documents that came from HTML and so for the printed version I do not
need the see also.

Are these possible?

Any help is appriciated.

Thanks,
Michael
 
J

Jezebel

Yes both are possible. Are you trying to write the code and are having
problems, or are you looking for someone to write the code for you? If the
former, post what you've done so far. If the latter, be aware that you're
asking quite a lot, particularly for the second one. You might get lucky
(some people write this sort of stuff for fun); but if it's a serious
requirement you might be better to pay for it.
 
G

Graham Mayor

Your first problem highlights the issues or manual formatting over styles.
What you need to do here is define the Heading 2 style as you want it to
appear then re-apply it to all the paragraphs that use it. You can do this
by macro -

Sub ReplaceExample()
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
'**********************
.Style = "Heading 2"
.Replacement.Style = "Heading 2"
'**********************
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
End With
Selection.Find.Execute replace:=wdReplaceAll
End Sub

The second problem is less simple as the concept of a 'page' in Word is
rather vague and depends on a variety of factors including the current
printer driver. You have not identified what constitutes a 'page' in this
context. You may find http://www.gmayor.com/replace_using_wildcards.htm
helpful in providing a replace function to add to the above macro that will
deal with this aspect.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

mmikedm1000

Thanks for the help. This made a big difference. Have a couple "easy"
questions. If I finding and replacing many different styles in a document,
is there a way tosetup a table of styles to find and replace? Or do I need
to have 15 different find/replace codes in my macro?

Second question, how do I error handle if the macro does not find a
particular style? This macro will be used for different docs and some may
not have the same styles. I want the macro to continue on if it does not
find a particular style. I have tried If - Than statements but to no avail.

Thanks,

Michael
 

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