Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2007

Tip: Looking for answers? Try searching our database.

Converting a word

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
LEU - 12 Jul 2007 20:52 GMT
I have the following macro that looks for a word in the document and replaces
it if it’s in a Heading style. The problem is it does not get all the words I
am looking for. How would I rewrite it to get all the words except if the
word is in a table, textbox or a graph?

Dim SearchRange As Range
Set SearchRange = ActiveDocument.Range
With SearchRange.Find
.Text = InputBox("Word to Bold and Cap:")
.MatchWholeWord = True
While .Execute
 Select Case SearchRange.Style
   Case "Heading 1", "Heading 2", "Heading 3", "Heading 4", "Heading 5",
"Heading 6", "Heading 7"
   SearchRange.Font.AllCaps = True
   SearchRange.Font.Bold = True
   Case Else
     'Do Nothing
 End Select
Wend
End With

LEU
Russ - 13 Jul 2007 00:39 GMT
You should use:
While .Execute = True
To do stuff only if something found.

You code is asking for a word or phrase to search for. If found, it checks
whether it is one of the heading styles. If it is a heading style, you try
to make Bold (already bold, isn't it?) and uppercase.

Did you want to expand to the whole paragraph, before doing that?
SearchRange.Expand Unit:=wdParagraph

But if you mess with the SearchRange range with expansion, then you should
reset it before the Wend with:
SearchRange.SetRange = Start:=SearchRange.End, End:=ActiveDocument.End

If a chart is in a frame, then this might be enough:

If Not SearchRange.Information(wdWithInTable) Or _
SearchRange.Information(wdFrameIsSelected) Then
...Select Case ...
End If

> I have the following macro that looks for a word in the document and replaces
> it if it¹s in a Heading style. The problem is it does not get all the words I
[quoted text clipped - 22 lines]
>
> LEU

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

LEU - 13 Jul 2007 02:42 GMT
Hi Russ,

That work great.  I did not know about the 'If Not SearchRange' statement.
It's great to learn new things.

Thank you for all your help again.
LEU

> You should use:
> While .Execute = True
[quoted text clipped - 44 lines]
> >
> > LEU
Russ - 13 Jul 2007 03:01 GMT
LEU,
You're Welcome.
I often learn while I help someone, too.

> Hi Russ,
>
[quoted text clipped - 54 lines]
>>>
>>> LEU

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.