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 / October 2006

Tip: Looking for answers? Try searching our database.

Tricky text manipulation problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gem_man - 17 Oct 2006 00:15 GMT
This is driving me nuts because I cannot even get off the starting grid.

I want to be able to programmatically go to each paragraph in large document
that starts with "Yummy Fruit" and is in style Header 2 (Yummy Fruit may
appear else where but wont be in Heading 2)

Then copy only the text that is in bold from the paragraph below and copy it
to the paragraph above "Yummy Fruit"

It sounds easy but I am darned if i can figure it out.

This is what it looks like before the code would act on it:-

Yummy Fruit (In style Heading 2)
1.  try eating (in non-bold) Oranges, Apples and Pears (in bold) they are
really good for you.

This is what I want:-

Oranges, Apples and Pears (anotherStyle)
Yummy Fruit (style Heading 2)
1.  try eating (in non-bold) Oranges, Apples and Pears (in bold) they are
really good for you.

Has anyone got any brilliant ideas to get me started? I really would be most
grateful

Regards
Jean-Guy Marcil - 17 Oct 2006 01:49 GMT
Gem_man was telling us:
Gem_man nous racontait que :

> This is driving me nuts because I cannot even get off the starting
> grid.
[quoted text clipped - 23 lines]
> Has anyone got any brilliant ideas to get me started? I really would
> be most grateful

Play arpound with someting like:

Sub Yummy()

Dim rgeDoc As Range
Dim rgePara As Range

Set rgeDoc = ActiveDocument.Range(0, 0)
With rgeDoc.Find
   .Text = "Yummy Fruit"
   .Style = ActiveDocument.Styles(wdStyleHeading2)
   Do While .Execute
       Set rgePara = .Parent.Paragraphs(1).Next.Range.Paragraphs(1).Range
       With rgePara.Find
           .Font.Bold = True
           .Execute
           If .Found Then
               With rgeDoc.Duplicate
                   .InsertBefore Chr(13)
                   .Collapse wdCollapseStart
                   .Style = "Normal"
                   .FormattedText = rgePara.FormattedText
               End With
           End If
       End With
       rgeDoc.Start = rgeDoc.End
   Loop
End With

End Sub

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Gem_man - 17 Oct 2006 09:01 GMT
Superb! Many many thanks Jean-Guy

> Gem_man was telling us:
> Gem_man nous racontait que :
[quoted text clipped - 57 lines]
>
> End Sub
Gem_man - 17 Oct 2006 18:40 GMT
Ok, I know this is cheeky, but acn anyone tell me how to get some text in
front of the text caption that has been moved to the paragraph above?

So it will now look like this?

Some suggested food Oranges, Apples and Pears (anotherStyle)
Yummy Fruit (style Heading 2)
1.  try eating (in non-bold) Oranges, Apples and Pears (in bold) they
are really good for you.

Thank you very much in advance

Adrian

> Gem_man was telling us:
> Gem_man nous racontait que :
[quoted text clipped - 57 lines]
>
> End Sub
Greg Maxey - 17 Oct 2006 19:01 GMT
Try:

Sub Yummy()
Dim rgeDoc As Range
Dim rgePara As Range
Set rgeDoc = ActiveDocument.Range(0, 0)
With rgeDoc.Find
   .Text = "Yummy Fruit"
   .Style = ActiveDocument.Styles(wdStyleHeading2)
   Do While .Execute
       Set rgePara =
.Parent.Paragraphs(1).Next.Range.Paragraphs(1).Range
       With rgePara.Find
           .Font.Bold = True
           .Execute
           If .Found Then
               With rgeDoc.Duplicate
                   .Collapse wdCollapseStart
                   .Move wdCharacter, -1
                   .Style = "Normal"
                   .InsertBefore Chr(13)
                   .FormattedText = rgePara.FormattedText
                   .InsertBefore "Some suggested foods "
               End With
           End If
       End With
       rgeDoc.Start = rgeDoc.End
   Loop
End With
End Sub

> Ok, I know this is cheeky, but acn anyone tell me how to get some text in
> front of the text caption that has been moved to the paragraph above?
[quoted text clipped - 78 lines]
> > jmarcilREMOVE@CAPSsympatico.caTHISTOO
> > Word MVP site: http://www.word.mvps.org 
Gem_man - 17 Oct 2006 19:27 GMT
Thanks Greg

Exactly as you had it didnt work quite right but with a bit of changing
around it works a treat.

Thanks for pointing me in the right direction

Regards
Adrian

> Try:
>
[quoted text clipped - 109 lines]
> > > jmarcilREMOVE@CAPSsympatico.caTHISTOO
> > > Word MVP site: http://www.word.mvps.org 

Rate this thread:






 
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.