Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word - Combine files

Status
Not open for further replies.

Andrzejek

Programmer
Jan 10, 2006
8,509
US
In Word, you can do:
Review - Compare (icon on Ribbon) - Combine...
that give you this dialog to Combine 2 files:

comb_uk7vst.png


Is there a way to Combine more than just 2 files? Like... 20?

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Unfortunately, no :-( Or... is it?
The macro below shows 'MergeDocuments', but I tried 'Combine'. What's the difference...[ponder]

I am trying to help a co-worker and she needs to 'Combine' many files (whatever this 'combine' does), but can only do 2 at the time, but she has 20 to do. And multiple times.

I did try to record a macro, so I can make it into a loop.

Code:
Sub CombineDocs()
    ChangeFileOpenDirectory "C:\Andy\Test\"
    Application.MergeDocuments OriginalDocument:=Documents("OriginalDoc.docx") _
        , RevisedDocument:=Documents("Document one.docx"), Destination:= _
        wdCompareDestinationOriginal, Granularity:=wdGranularityWordLevel, _
        CompareFormatting:=True, CompareCaseChanges:=True, CompareWhitespace:= _
        True, CompareTables:=True, CompareHeaders:=True, CompareFootnotes:=True, _
        CompareTextboxes:=True, CompareFields:=True, CompareComments:=True, _
        CompareMoves:=True, OriginalAuthor:="MyOriginal", RevisedAuthor:= _
        "MyRevDoc", FormatFrom:=wdMergeFormatFromPrompt
End Sub

But even recorded macro did not work when I tried to run it. It gave me 'bad file name' Run-time error '4160' with a whole bunch of code highlighted. There are only 2 places with 'file name' in this macro, so - who knows what the issue was.

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Well, I have this code. It does not crash, and it does 'something'...
I just need to wait to see if what it 'does' is what she needs (and it is weekend)

Code:
Sub CombineDocs()
Dim MyPath As String
Dim fileName1 As String
Dim fileName2 As String
Dim doc1 As Document
Dim doc2 As Document

Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)

With fDialog
    .AllowMultiSelect = False
    .Filters.Add "Word files", "*.docx; *.doc", 1
    .Title = "Select Original Document"
    .Show
    fileName1 = .SelectedItems(1)
End With

Set doc1 = Documents.Open(fileName1)
MyPath = doc1.Path & "\"

fileName2 = MyPath & Dir(MyPath)

Do While fileName2 <> "" And fileName2 <> fileName1
    Set doc2 = Documents.Open(fileName2)

    ChangeFileOpenDirectory MyPath
    Application.MergeDocuments OriginalDocument:=Documents(doc1) _
        , RevisedDocument:=Documents(doc2), Destination:= _
        wdCompareDestinationOriginal, Granularity:=wdGranularityWordLevel, _
        CompareFormatting:=True, CompareCaseChanges:=True, CompareWhitespace:= _
        True, CompareTables:=True, CompareHeaders:=True, CompareFootnotes:=True, _
        CompareTextboxes:=True, CompareFields:=True, CompareComments:=True, _
        CompareMoves:=True, OriginalAuthor:="MyOriginal", RevisedAuthor:= _
        "MyRevDoc", FormatFrom:=wdMergeFormatFromPrompt
    doc2.Close
    doc1.Save
    fileName2 = MyPath & Dir
Loop

End Sub

I hate to 'guess' because at this time, I don't know what I am doing... [mad]

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Andy, is the Combine/Compare or Combine/Append?

Or maybe I'm barkin' up the wrong tree.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

You Matter...
unless you multiply yourself by the speed of light squared, then...
You Energy!
 
I can't imagine what does mean "combine" when it's not he same as "merge" .. where is the difference ..
 
@mikrom
An example of combining document revisions, by MS, here. For more documents and manual process the documents are combined one by one.

combo
 
Skip: Combine/Compare or Combine/Append?
I don't really know. All what it is, it's 'MergeDocuments' anyways...
But all what I know - she is trilled and as happy as she can be (with this Macro) [thumbsup2]
Some 'weird' things happen to those documents, but that's because there are images in the headers that Word just repeats, and some other 'corky' pieces that Word doesn't know how to interpret, but she is happy to do some manual editing.

What's funny, she's even tried Chat GPT and she's got some answers (code). She did not try that code (yet...?) :)

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
What puzzles me is "combining" 20 documents.

What a Merge! (spoken like Yakov Smirnoff)

When I think of "comparing" multiple documents, New Testament Greek manuscript critical text analysis comes to mind where there are about 138,000 words in the Greek NT and about 400,000 variants. And that's because there are more than 5,800 manuscript copies extant between 150AD - 1400.



Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

You Matter...
unless you multiply yourself by the speed of light squared, then...
You Energy!
 
I believe the issue is: some 'outside' people (consultants) instead of working out of the same (one) file (on SharePoint), they copied the original file to make their 'changes'. And next time around, they 'copied' last version of the Word doc and made additional changes, And so on...

You end up with 20+ 'unrelated' Word docs, depending on how long this process took place. But somebody wants to have just one Word document with all changes (versions) in it and what was there originally, etc.

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Do they need references to which outside entity contributed whatever change?

Otherwise, "anonymous sources report that..."

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

You Matter...
unless you multiply yourself by the speed of light squared, then...
You Energy!
 
Not really. They just work with 1 Consultant (and pretty much one person from Consultants) so she does know who made the change(s).

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Where does 20 combines come in?

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

You Matter...
unless you multiply yourself by the speed of light squared, then...
You Energy!
 
I told her to have all Docs (to be 'combined') in one folder, and either use the 'original' file to start with (or empty, saved file). All other files will be processed in alphabetical order from that folder. I would guess the order of those 'combines' matter.
I did tell her to run some sample on just a few (3 or 4) files to make sure what she gets is what she needs. A lot easier to see if it works OK.

You see in the code [tt]doc1[/tt] is the file that is saved after each 'combine'. I don't know if that's needed, but just to be on the safe side, I saved it (often).

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top