Link to home
Start Free TrialLog in
Avatar of sscottincanyon
sscottincanyon

asked on

Automatically Extract last 50 pages of mutliple documents

I feel this to be a extremely difficult problem. I have searched through Expert Exhange and numerous other website and forums. It is extremely urgent as my client needs this project completed.
I have several thousand .rtf files that I need to copy the last 50 pages of each file into another file so as to end up with several thousand files of 50 pages each, but only the last 50 pages. The files are various sizes. If I were after the first 50 pages, or if they were all identical size, this would be a no brainer. This needs to be automated to run through all several thousand files.
Avatar of mish33
mish33
Flag of United States of America image

Use i.e. MS Word to paginate whole document and cut last 50 pages to a new doc, repeat for each doc.
ASKER CERTIFIED SOLUTION
Avatar of billmercer
billmercer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sscottincanyon
sscottincanyon

ASKER

Thanks for the help. The macro works great on a single document. I guess I am still not quite getting it. I have not been able to get the "for each" loop to work within the macro.  I have tried starting with

 strDoc = Dir(Path & "*.Doc")
    Do While strDoc <> ""

 and have tried various combinations to complete the loop, but it just isn't working. Any ideas? This is critical as I have over 14,000 documents and even the open, click, open, click will just take too long.
Here is what I have so far and the error I am getting back.

Sub SaveLast24()

Dim Path As String
Dim strDoc As String
Dim Doc As Document

 Path = "c:\ahg_files_orig\test_group"
 strDoc = Dir(Path & "*.rtf")
 
 
   Do While Doc <> ""
   Set Doc = Documents.Open(FileName:=Path & Doc)

   
   Selection.EndKey Unit:=wdStory
   For i = 1 To 23
     Application.Browser.Previous
   Next i
   Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
   Selection.Delete
   ActiveDocument.Save
   
   Doc.Close
   strDoc = Dir
Loop
End Sub


Error when running:
Run-time error 91
Object variable or With block variable not wet

Bill Mercer:
Thank you for the guidance on creating this VB Macro, with a little tweaking and adding in a loop control it is humming right along. Now all I have to do is convert all the documents to use arial instead of the awful font that it is defaulted with.

Again I really appreciate the help and the stellar job!!!

THANK YOU!!!!

Shon
Glad to hear it worked for you. Thanks.