Results 1 to 13 of 13
  1. #1
    3 Star Lounger
    Join Date
    Jul 2008
    Location
    Suffolk, United Kingdom
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Find duplicate files and merge (2003)

    Hi is it possible to find duplicate .doc filenames (contents are not the same) and merge the duplicates to a master file automatically either through other software, access or word

    Many thanks
    Regards
    Gerbil (AKA Kevin)

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Find duplicate files and merge (2003)

    What exactly do you mean by "merge the duplicates to a master file"?

  3. #3
    3 Star Lounger
    Join Date
    Jul 2008
    Location
    Suffolk, United Kingdom
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find duplicate files and merge (2003)

    For example:
    Everytime we send a letter to a client we append it to the bottom of an exsiting .doc file however over the years different secretaries have been filling under there own folder instead of appending the original.

    So...

    Folder A has a .doc file called 123456.doc with letters for say 3 years.
    Folder B has a file also called 123456.doc with more letters over many years.
    Folder C has a file also called 123456.doc with more letters over many years.

    I want to take 123456.doc in folder C and B and append them to the bottom of 123456.doc in folder A, I can't open each and copy paste because there are 22 departments and 4500 duplicates in just one of these departments.

    I was hoping the would be some sort of access/vba/word way to automate this. Where I could just select the two folders and it would scan for duplicate filenames and append one to the other.

    Once again thanks Hans
    Regards
    Gerbil (AKA Kevin)

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Find duplicate files and merge (2003)

    In your thread beginning at <post:=722,479>post 722,479</post:> in the Access forum you told us that you have a rather complicated folder structure for storing the documents. Should the code search through this folder structure, or will the search be limited to a pair of folders (specified by the user) at a time?

  5. #5
    3 Star Lounger
    Join Date
    Jul 2008
    Location
    Suffolk, United Kingdom
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find duplicate files and merge (2003)

    <P ID="edit" class=small>(Edited by kemorr on 22-Jul-08 15:49. Additional information)</P>Yes it is complicated. We are in the process of moving all files into a central location which is:
    O:LETTERSThen the specific departmentthen CRN Comm #123456.doc

    We have managed to move a single copy of each CRN into the final destination folder, then we have a folder called duplicates which contains the files we need to match to the first file by there .doc filename. There is one duplicates folder for each department so I would like to be able to select a master directory and then select the duplicate directory and have it match and append the files by filename.

    I'm open to suggestions

    Really thanks so much Hans

    Just to complicate things even more!! Is it possible for the code to scan the word document looking for a date and then append to the master file in date order. I'm convinced this whole task is almost impossible to do.

    Thanks
    Regards
    Gerbil (AKA Kevin)

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Find duplicate files and merge (2003)

    You write "to select a master directory and then select the duplicate directory". At what level would these folders be exactly? At the department level, or...?

  7. #7
    3 Star Lounger
    Join Date
    Jul 2008
    Location
    Suffolk, United Kingdom
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find duplicate files and merge (2003)

    They would be in subdirectory's of the directory 'duplicates'. If I were to be able to limit the search criteria for example 'search duplicate folders for CRN comencing 1. The I could point the destination to the folder beginning CRN 1, if not then it would need to search both duoplicate and destination, find a match, and append the file.

    I will be doing them one department at a time so no need for department filters etc.

    Sorry, Hans I have chalenged you this time!!

    Many thanks, I am learning a lot from you! Thank you
    Regards
    Gerbil (AKA Kevin)

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Find duplicate files and merge (2003)

    Try the code in the attached text file. It is intended to be used as a macro from within Word. When you run the macro, it will prompt you to select the source folder (the one containing the duplicates) and the target folder (where everything should end up).

    It doesn't attempt to sort the documents by date.

    Please test the macro on duplicates of the folders involved first, before letting it loose on the "real" folders!
    Attached Files Attached Files

  9. #9
    3 Star Lounger
    Join Date
    Jul 2008
    Location
    Suffolk, United Kingdom
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find duplicate files and merge (2003)

    Thats great thank you so much. I am creating test folders now to try it out. Is it possible to make it so that if the .doc file begins '00' it will check the destination of a folder
    'CRN 00' and if the file begins 01 goes to 'CRN 01' and so on upto 'CRN 99' because there are around 150'000 files per department we put them in subdirectory's based on the first 2 digits of there CRN number.

    Many many thanks
    Regards
    Gerbil (AKA Kevin)

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Find duplicate files and merge (2003)

    Try the attached version - once again, test it on a duplicate of the folder structure first!
    Attached Files Attached Files

  11. #11
    3 Star Lounger
    Join Date
    Jul 2008
    Location
    Suffolk, United Kingdom
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find duplicate files and merge (2003)

    Hi Hans, you really are a genius that script will save weeks of copy and paste and possible human errors...

    One problems with the second script is, when it finds a file in the duplicates directory that actually isn't a duplicate it was put the by mistake it gives a message object deleted and goes to the vba code.

    Is it possible to get it to page break before the letter is merged?

    Lastly I would like to make a way to prevent us accidently running the script over the same directory twice, is it possibe to delete the completed file without confirmation after the merge is complete. We take backups every night so if the worst happens on the live run we would have are backups.

    Where did you learn all this stuff, I starting out in this carrer your like a Bible for VBA many thanks.
    Regards
    Gerbil (AKA Kevin)

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Find duplicate files and merge (2003)

    1) Can you explain more clearly when you get an error? I tested the code on folders where there are documents without a match on either side and didn't get an error.

    2) Is it possible to get it to page break before the letter is merged?

    Replace the line
    <code>
    Selection.InsertParagraphAfter
    </code>
    with
    <code>
    Selection.InsertBreak Type:=wdPageBreak
    </code>
    3) If you want to delete the source file, insert the line
    <code>
    Kill strsource & strDocName
    </code>
    above the line
    <code>
    ' On to the next one
    </code>
    4) Where did you learn all this stuff

    Mostly by reading the help files <img src=/S/grin.gif border=0 alt=grin width=15 height=15> (They were *much* better in older versions of Word). And here in Woody's Lounge, of course.

  13. #13
    3 Star Lounger
    Join Date
    Jul 2008
    Location
    Suffolk, United Kingdom
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find duplicate files and merge (2003)

    Hi Hans,

    Many thanks the error was my fault its working great, better than expected. And thanks for the link in my other post, I can now type my letters in access using DLookup that you showed me in yet another post to auto-fill the letter based on user selections, and then save as a word doc.

    Thank you again.
    Regards
    Gerbil (AKA Kevin)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •