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 / March 2007

Tip: Looking for answers? Try searching our database.

Character by character search for direct formatting

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mickmoo - 18 Mar 2007 10:56 GMT
Hi,

Forgive my ignorance but I am new to Word Programming.

I need to be able to search a document character by character. If the
Character is formatted as "Dark Blue" in colour I need to extract the
character from the source document to a new document (target) and continue
search and extract until the end of the source document is reached.

I know this request may sound a bit odd, so here's the reason why.

I've written a book (approximately 280000 words - 640 pages) and I want to
be able to extract just the Dialogue (enclosed by single quotation marks and
formatted in Dark blue, so that it stands out from the narrative)

The entire source document is written in font : Times New Roman, regular, 12
point
I have only used the "normal" paragraph style.

The situation is complicated by that the fact that only part of any given
paragraph may be dark blue (dialogue) which the rest is Black (narrative)

What I'm hoping for is a single target document that contains just the
dialogue (Dark Blue text)

Any thoughts on this conundrum would be much appreciated.

Mnay thanks
Lene Fredborg - 18 Mar 2007 12:44 GMT
I think the macro below will do what you want. The macro creates a new
document and uses Find to get all dark blue text strings and inserts each
string into the new document. Two paragraph marks are added after each string
in order to make sure they are properly separated (since I don’t know how
your document is formatted).

See this article if you need help on installing macros:
http://www.gmayor.com/installing_macro.htm

Sub ExtractBlueTextToNewDocument()

   Dim oDoc As Document
   Dim oNewDoc As Document
   Dim oBlueRange As Range
   Dim n As Long
   
   Set oDoc = ActiveDocument
   'Create document to be used for extraction of blue text
   Set oNewDoc = Documents.Add
   
   oDoc.Activate
   Selection.HomeKey (wdStory)
   With Selection.Find
       .ClearFormatting
       .Text = ""
       .Font.Color = wdColorDarkBlue
       .Forward = True
       .Wrap = wdFindStop
       Do While .Execute
           Set oBlueRange = Selection.Range
           'Insert selected text in oNewDoc - end with 2 paragraph marks
           oNewDoc.Content.InsertAfter oBlueRange.Text & vbCr & vbCr
           'Count how many text strings found
           n = n + 1
       Loop
   End With
   
   'Activate the new document
   oNewDoc.Activate
   
   'Clean up
   Set oDoc = Nothing
   Set oNewDoc = Nothing
   Set oBlueRange = Nothing
   Selection.Find.ClearFormatting
   
   'Finished - show message
   MsgBox "Finished extracting " & n & " blue text strings to new document."
   
End Sub

Signature

Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word

> Hi,
>
[quoted text clipped - 24 lines]
>
> Mnay thanks
Mickmoo - 18 Mar 2007 15:27 GMT
Thanks Lene

You are a real lifesaver. You code worked like a dream.
I converted the sub to a function and ran it from the immediate window and
low and behold I had a new document containing all my dialogue!
I'm cuurently in the middle of editing my book and this will allow me to
accurately gauge the proportion of dialogue to narrative.

Once again many thanks.

> I think the macro below will do what you want. The macro creates a new
> document and uses Find to get all dark blue text strings and inserts each
[quoted text clipped - 75 lines]
> >
> > Mnay thanks
Lene Fredborg - 18 Mar 2007 15:38 GMT
Thank you for the feedback. I am glad I could help you.
I wish you luck with your book.

Signature

Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word

> Thanks Lene
>
[quoted text clipped - 85 lines]
> > >
> > > Mnay thanks
 
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.