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

Tip: Looking for answers? Try searching our database.

Copy information between style

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jaypee - 24 Apr 2006 08:47 GMT
I have an existing word document and I want to lift all the data which does
not have the style "Heading 1" and paste it into a new document.

This works fine by iterating thru the document and checking for
Paragraph.Style

the problem right now is that it converts tables into text, each field is
converted as a single paragraph.

Is there something I can do to work around this? thanks
Jaypee - 24 Apr 2006 09:11 GMT
Here is the code I am using... breaks when it encounters tables :(

Sub CopyData()
   Dim docSource As Document
   Dim docDest As Document
   Dim Paragraph As Paragraph
   Dim tmpName As String
   
 
   Set docSource = ActiveDocument
   Set docDest = Documents.Add
 
     
   For Each Paragraph In docSource.Paragraphs
       docSource.Activate
       If Paragraph.Style <> docSource.Styles(wdStyleHeading1) Then
           Paragraph.Range.Select
           Paragraph.Range.Copy
           
           docDest.Activate
           Selection.Paste
           Selection.EndKey unit:=wdLine
       End If
   Next

   Set docSource = Nothing
   Set docDest = Nothing
End Sub
Dave Lett - 24 Apr 2006 13:22 GMT
Hi,

I think you might be making this more difficult (and longer) than it needs
to be:

With Selection
   .HomeKey Unit:=wdStory, Extend:=wdMove
   With .Find
       .ClearFormatting
       .Text = ""
       .Style = "Heading 1"
       With .Replacement
           .ClearFormatting
           .Text = ""
       End With
       .Execute Replace:=wdReplaceAll
   End With
End With
ActActiveDocument.SaveAs _
   FileName:=ActiveDocument.Path & _
   Replace(ActiveDocument.Name, ".doc", "_NoHeading1.doc")

This routine replaces any "Heading 1" formatted paragraph with ... nothing.
That is, it removes all the "Heading 1" paragraphs. The last line of the
routine saves the document

HTH,
Dave

> Here is the code I am using... breaks when it encounters tables :(
>
[quoted text clipped - 22 lines]
>    Set docDest = Nothing
> End Sub
Jaypee - 25 Apr 2006 04:55 GMT
Thanks Dave, this is an elegant solution to the problem I originally portrayed.

Unfortunately, I did not elaborate the entire scenario I am dealing with....

I have one master document and several source documents.. for all comparison
purposes, they have the same number of Sections. Sections are differentiated
by the  headers (having "Heading 1" style).

That is the reason I was using the paragraph style to lift out the
paragraphs in between -- the next step was to paste it in the corresponding
section.

Anyway, thanks... given the lack of context I provided, the solution you
gave was excellent.
 
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.