rodrigobele
02-05-2016, 01:14 PM
Dear Word VBA coders,
I have the following code which compares word documents from one folder with documents with the same filename in another folder, highlights eventual changes and saves them in another document in a 3rd folder.
I'm still an amateur coder. I can work the ifs and the for/while loops, but I'm far from getting acquainted with the majority of VBA commands and objects.
Is it possible to alter this macro so that it skips documents which doesn't have a corresponding one in the second folder (instead of terminating the macro execution with an error) and so that it only saves the documents which were actually changed in the 3rd folder?
I appreciate any help, even if you just point me to word documentation.
Cordially,
Rodrigo
Sub Compare_Docs()
cpath = "U:\TURMAS\10ATURMA\Rodrigo\Pasta1\"
inpath = "U:\TURMAS\10ATURMA\Rodrigo\Pasta2\"
outpath = "U:\TURMAS\10ATURMA\Rodrigo\Pasta3\"
fname = Dir(inpath & "*.jus")
Do While Len(fname) > 0
Set doc = Documents.Open(inpath & fname)
doc.Compare cpath & fname
doc.Merge inpath & fname
doc.SaveAs outpath & fname
doc.Close
fname = Dir
Loop
End Sub
I have the following code which compares word documents from one folder with documents with the same filename in another folder, highlights eventual changes and saves them in another document in a 3rd folder.
I'm still an amateur coder. I can work the ifs and the for/while loops, but I'm far from getting acquainted with the majority of VBA commands and objects.
Is it possible to alter this macro so that it skips documents which doesn't have a corresponding one in the second folder (instead of terminating the macro execution with an error) and so that it only saves the documents which were actually changed in the 3rd folder?
I appreciate any help, even if you just point me to word documentation.
Cordially,
Rodrigo
Sub Compare_Docs()
cpath = "U:\TURMAS\10ATURMA\Rodrigo\Pasta1\"
inpath = "U:\TURMAS\10ATURMA\Rodrigo\Pasta2\"
outpath = "U:\TURMAS\10ATURMA\Rodrigo\Pasta3\"
fname = Dir(inpath & "*.jus")
Do While Len(fname) > 0
Set doc = Documents.Open(inpath & fname)
doc.Compare cpath & fname
doc.Merge inpath & fname
doc.SaveAs outpath & fname
doc.Close
fname = Dir
Loop
End Sub