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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Comparisons Macro

Status
Not open for further replies.

sshakey

Technical User
Mar 26, 2001
3
AU
My goal is to write a macro to automate a difference between director(y/ies) of word documents.

I have been playing around with a few things to no success, have got the macro running to compare files and so forth but that is still pretty manual and not through the entire directory.

Any suggestions, would be much appreciated?
 
Do you want to find differences in filenames or contents of the word files?
 
differences in the word documents themselves. it can be done file by file by using the compare function (using revisions) but that is too time consuming and still much of a manual process.

has anyone done something smiliar to this before?


 
Not 100% sure this works but it should give you some idea how I would do it.

I ran it and it errored on the Compare function. I believe this is because my MSOffice isn't setup up to use this. It told me to run setup, which I can't do because I am at work.

Dim NumberOfFiles As Integer
Dim FoundFiles() As String

Private Sub GO()
Call GetDocs
Call CompareFiles
End Sub

Private Sub GetDocs()
Set fs = Application.FileSearch
With fs
.LookIn = "C:\"
.FileName = "*.doc"
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then

NumberOfFiles = .FoundFiles.Count

ReDim Preserve FoundFiles(NumberOfFiles)

For i = 1 To NumberOfFiles
FoundFiles(i) = .FoundFiles(i)
Next i

Call CompareFiles
Else
MsgBox "There were no files found."
End If
End With
End Sub


Private Sub CompareFiles()
For i = 1 To NumberOfFiles
Documents.Open (FoundFiles(i))

For x = 1 To NumberOfFiles
If x <> i Then ActiveDocument.Compare Name:=FoundFiles(x)
Next x

ActiveDocument.Close
Next i
End Sub


If you have any problems let me know =)
 
The code above will compare every doc with every other doc. Not sure if you wanted that. You should be able to change the code in the CompareFiles sub to compare the files you want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top