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 / August 2005

Tip: Looking for answers? Try searching our database.

find formatted text

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dig-IT - 05 Aug 2005 01:05 GMT
Hi,

I need to do an automatic search/replace with a macro that i cannot record:

- i want to find all the occurrences where the space between a bold and
non-bold word is formatted as bold
- i want to change the formatting for that space as non-bold

e.g.:
<bold>someWord[space]</bold>someOtherword should become
<bold>someWord</bold>[space]someOtherword

<bold>someWord[space]someOtherword</bold> should remain intact

Any help would be highly appreciated!
Cheers,
Jos
Greg Maxey - 05 Aug 2005 01:42 GMT
This is pretty crude but might serve your purposes:

Sub Test()
Dim oWord As Word.Range
On Error Resume Next
For Each oWord In ActiveDocument.Range.Words
 If Not oWord.Next.Font.Bold = True Then
   oWord.Collapse Direction:=wdCollapseEnd
   oWord.MoveStart Unit:=wdCharacter, Count:=-1
   oWord.Font.Bold = False
 End If
Next

End Sub

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Hi,
>
[quoted text clipped - 13 lines]
> Cheers,
> Jos
Klaus Linke - 05 Aug 2005 04:54 GMT
Hi Jos,

Another method I use a lot for stuff like this is to put in tags
temporarily.

In your case,
1)
Find what:  ((leave empty, Format > Font: check "Bold", or use Ctrl+B))
Replace with: <b>^&</b>  ((use Ctrl+B twice so it says "not bold"))
... then "Replace all".
2)
Replace "<b> </b>" with a space. (("Clear formatting" if neccessary))
3)
With "Match wildcards" checked,
Find what: \<b\>(*)\</b\>
Replace with: \1 ((use Ctrl+B once so it says "bold"))

Looks a bit complicated, but if you've done replacements like this a few
times, it's a breeze.

Regards,
Klaus

> Hi,
>
[quoted text clipped - 14 lines]
> Cheers,
> Jos
Dig-IT - 05 Aug 2005 10:00 GMT
Hi Klaus,

Thanks a lot, this works perfectly _and_ i can understand it too (with
my limited VBA knowledge)

This method actually introduces new (formatted) spaces to the final
text, but they can be prevented by some intermediate search/replace
functions (see below).

FYI: I'm enhancing a Word2Wiki macro for automatic translation of a .doc
to the TWiki markup language:
http://twiki.org/cgi-bin/view/Plugins/MsWordToTWikiMLAddOn

Thanks again,
Jos

----------------reworked f&r sequence
- insert tags
find: (Bold empty)
repl: <b>^&</b> (not bold)

- remove all 'loose' formatted spaces
find: <b> </b>
repl: (Clear formatting)

-leading spaces
find: \<b\>( @)<
repl: <b>

-trailing spaces
find: (>)( @)(\</b\>)
repl: </b>

- add missing spaces
find: (>)\<b\>
repl: \1 <b>

find: \</b\>(<)
repl: </b> \1

- remove tags
find: \<b\>(*)\</b\>
repl: \1 (Bold)

> Hi Jos,
>
[quoted text clipped - 37 lines]
>>Cheers,
>>Jos
 
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.