Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Automatically Extract last 50 pages of mutliple documents

Posted on 2006-06-02
6
Medium Priority
?
292 Views
Last Modified: 2010-04-17
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.
0
Comment
Question by:sscottincanyon
  • 3
  • 2
6 Comments
 
LVL 15

Expert Comment

by:mish33
ID: 16821933
Use i.e. MS Word to paginate whole document and cut last 50 pages to a new doc, repeat for each doc.
0
 
LVL 19

Accepted Solution

by:
billmercer earned 2000 total points
ID: 16822271
This should be easy to do as a macro. You can use the macro recording feature to create most of it, and then just insert a few tweaks to make it more flexible.

Basically, you create a macro that goes to the very end of the document, then backs up 50 pages, starts a selection, jumps to the beginning of the document, and deletes the selection. At this point you then have a document with just the last fifty pages.
Then you just save the document with a modified filename.
Assign this macro to a button on a toolbar, and then open each file and click the button, open and click, open and click, etc.

Here's a quick example...

Sub SaveLast50()

    TruncatedFileName = "Last50PagesOf" & ActiveDocument.Name
    Selection.EndKey Unit:=wdStory
    For i = 1 To 49
      Application.Browser.Previous
    Next i
    Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
    Selection.Delete
    ActiveDocument.SaveAs FileName:=TruncatedFileName
End Sub

To make this more automatic, it's not too difficult to add a "for each" loop to the macro so that it will process every file in a folder.
0
 
LVL 2

Author Comment

by:sscottincanyon
ID: 16823290
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.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:sscottincanyon
ID: 16823315
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

0
 
LVL 2

Author Comment

by:sscottincanyon
ID: 16824196
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
0
 
LVL 19

Expert Comment

by:billmercer
ID: 16851746
Glad to hear it worked for you. Thanks.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Introduction to Processes

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question