Compiling several "booklets", each containing 100-articles made by avery tedious method. Hoping I ca

J

John

I have made some screenshots/photos to help illustrate my task

Please see:

http://www.dropbox.com/gallery/5546881/2/generic/how-do-i-automate-this?h=e50bab

Could you kindly look at:

1-the-spreadsheet.jpg
2-the-giant-word-document.jpg


The annotations on the screenshots illustrate what I need to do.

Here is a quick summary
- A list of articles has been decided by a 3rd party. (the spreadsheet
contains this list)
- I need to build a NEW word document
- This Word document is built by copying&pasting specific pages from
the "giant" word document.



I'd be grateful for any hints, tips or advice on how to approach
this.

Thanks so much
 
G

Graham Mayor

This should be reasonably straightforward to achieve, but you need to
clarify what constitutes an article. Word is not a page layout application
but is text flowed to the margins of the document layout. How is the end of
the article determined, and when the new document is created, do you want
each article to begin a new page?
By default the new document would be based on the normal template (as I
guess you don't have access to the original third party template) so the new
document pages may not take up exactly the same amount of space. How do you
want to deal with that?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
J

Jef Gorbach

Just thinking out-loud, but your description sounds like this is a
recurring project in -- in which case, I wonder if it wouldn't it be
faster/easier in the long-haul to separate the massive word document
into its component articles using the article# for each filename.
Granted this might take some time initially, but i would think the
group here could help code a routine to do it.

Thereafter you would be able to combine the client(s)'s selected
articles for their customized booklets, If mail-merge isnt upto the
task, it shouldn't be too difficult to code a loop thru the
spreadsheet, copying the selected articles to a temp subdirectory then
combine the selections into a single document for your client.
http://www.gaebler.com/How-to-Combine-Multiple-Word-Documents-into-One-Document.htm
 
G

Graham Mayor

Based on your linked graphics, copy the column of the table containing the
article numbers you wish to include to a single column Word table and save
that document. Then run the following macro having first changed the two
paths to those of your new table and A COPY OF your master document.


Dim MainDoc As Document
Dim TargetDoc As Document
Dim DataDoc As Document
Dim oTable As Table
Dim oArticle As Range
Dim oRng As Range
Dim oTargetRng As Range
'open the document containing the articles
Set MainDoc = Documents.Open("D:\My Documents\Test\Articles Test.docx")
'open the document containing the list
Set DataDoc = Documents.Open("D:\My Documents\Test\3805.docx")
'open a new document to take the required articles
Set TargetDoc = Documents.Add
Set oTable = DataDoc.Tables(1)
For i = 1 To oTable.Rows.Count
Set oArticle = oTable.Cell(i, 1).Range
oArticle.End = oArticle.End - 1
MainDoc.Activate
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(findText:="Article: " & oArticle)
Set oRng = Selection.Range.Bookmarks("\page").Range
Set oTargetRng = TargetDoc.Range
oTargetRng.InsertAfter oRng.FormattedText
oTargetRng.Collapse wdCollapseEnd
oTargetRng.InsertBreak wdSectionBreakNextPage
Exit Do
Loop
End With
End With
Next i

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
J

John

Based on your linked graphics, copy the column of the table containing the
article numbers you wish to include to a single column Word table and save
that document. Then run the following macro having first changed the two
paths to those of your new table and A COPY OF your master document.

Dim MainDoc As Document
Dim TargetDoc As Document
Dim DataDoc As Document
Dim oTable As Table
Dim oArticle As Range
Dim oRng As Range
Dim oTargetRng As Range
'open the document containing the articles
Set MainDoc = Documents.Open("D:\My Documents\Test\Articles Test.docx")
'open the document containing the list
Set DataDoc = Documents.Open("D:\My Documents\Test\3805.docx")
'open a new document to take the required articles
Set TargetDoc = Documents.Add
Set oTable = DataDoc.Tables(1)
For i = 1 To oTable.Rows.Count
    Set oArticle = oTable.Cell(i, 1).Range
    oArticle.End = oArticle.End - 1
    MainDoc.Activate
    With Selection
        .HomeKey wdStory
        With .Find
            .ClearFormatting
            .Replacement.ClearFormatting
            Do While .Execute(findText:="Article: " & oArticle)
                Set oRng = Selection.Range.Bookmarks("\page").Range
                Set oTargetRng = TargetDoc.Range
                oTargetRng.InsertAfter oRng.FormattedText
                oTargetRng.Collapse wdCollapseEnd
                oTargetRng.InsertBreak wdSectionBreakNextPage
                Exit Do
            Loop
        End With
    End With
Next i

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>







- Show quoted text -

Wow! It seems to work. I'm stunned.

There is a problem though:

- the formatting/styles to have been stripped. Is there anyway I can
preserve the original formatting?

(also, there are a bunch of blank pages; something I can easily delete
by hand. Probably caused by wonky formatting of my big document)
 
G

Graham Mayor

John said:
Wow! It seems to work. I'm stunned.
There is a problem though:
- the formatting/styles to have been stripped. Is there anyway I can
preserve the original formatting?
(also, there are a bunch of blank pages; something I can easily delete
by hand. Probably caused by wonky formatting of my big document)

The following will retain the formatting within the parameters of the styles
in the template of the new document. Without knowing how the blank pages are
created (not by this macro) it is diffiocult to determine a way to remove
them.

Dim MainDoc As Document
Dim TargetDoc As Document
Dim DataDoc As Document
Dim oTable As Table
Dim oArticle As Range
Dim oRng As Range
Dim oTargetRng As Range
'open the document containing the articles
Set MainDoc = Documents.Open("D:\My Documents\Test\Articles Test.docx")
'open the document containing the list
Set DataDoc = Documents.Open("D:\My Documents\Test\3805.docx")
'open a new document to take the required articles
Set TargetDoc = Documents.Add
Set oTable = DataDoc.Tables(1)
For i = 1 To oTable.Rows.Count
Set oArticle = oTable.Cell(i, 1).Range
oArticle.End = oArticle.End - 1
MainDoc.Activate
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(findText:="Article: " & oArticle)
Set oRng = Selection.Range.Bookmarks("\page").Range
oRng.Copy
Set oTargetRng = TargetDoc.Range
oTargetRng.Collapse wdCollapseEnd
oTargetRng.Paste
Set oTargetRng = TargetDoc.Range
oTargetRng.Collapse wdCollapseEnd
oTargetRng.InsertBreak wdSectionBreakNextPage
Exit Do
Loop
End With
End With
Next i
DataDoc.Close wdDoNotSaveChanges
MainDoc.Close wdDoNotSaveChanges

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
J

John

The following will retain the formatting within the parameters of the styles
in the template of the new document. Without knowing how the blank pages are
created (not by this macro) it is diffiocult to determine a way to remove
them.

Dim MainDoc As Document
Dim TargetDoc As Document
Dim DataDoc As Document
Dim oTable As Table
Dim oArticle As Range
Dim oRng As Range
Dim oTargetRng As Range
'open the document containing the articles
Set MainDoc = Documents.Open("D:\My Documents\Test\Articles Test.docx")
'open the document containing the list
Set DataDoc = Documents.Open("D:\My Documents\Test\3805.docx")
'open a new document to take the required articles
Set TargetDoc = Documents.Add
Set oTable = DataDoc.Tables(1)
For i = 1 To oTable.Rows.Count
    Set oArticle = oTable.Cell(i, 1).Range
    oArticle.End = oArticle.End - 1
    MainDoc.Activate
    With Selection
        .HomeKey wdStory
        With .Find
            .ClearFormatting
            .Replacement.ClearFormatting
            Do While .Execute(findText:="Article: " & oArticle)
                Set oRng = Selection.Range.Bookmarks("\page").Range
                oRng.Copy
                Set oTargetRng = TargetDoc.Range
                oTargetRng.Collapse wdCollapseEnd
                oTargetRng.Paste
                Set oTargetRng = TargetDoc.Range
                oTargetRng.Collapse wdCollapseEnd
                oTargetRng.InsertBreak wdSectionBreakNextPage
                Exit Do
            Loop
        End With
    End With
Next i
DataDoc.Close wdDoNotSaveChanges
MainDoc.Close wdDoNotSaveChanges

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

I see that in this code there is a reference to the Excel spreadsheet.
So, do I still need to create a copy the column of the table that
contains the article numbers I need to include to a single column Word
table and save that document?

Thanks
 
Top