Hi!
I am new here. I sometimes need to use VBA in Word 2007 (i am not a great programmer) and now i need to write VBA for comparing files in two folders (both includes the same files, one new and second older). I need to automaticaly compare it, and for the best, in third folder create documents with changes (where.
But i cannot write the method Application.CompareDocuments without opening documents (it doesn't work). If i opened dokuments, then it works, but for 700 files it will be very slowly. There is one more complication, these documents are made from external program and when is the document opened in the Word, the Word ask for contacting the database, i must press Esc, then is the document opened (type is *.rtf).
This works:
*** Code Start
Sub porovnani_souboru()
'
' porovnani_souboru Makro
'
'
Dim myFile As String
Dim Original As Document
Dim Copy As Document
myFile = Dir("C:\TestA\*.rtf")
While myFile <> ""
Set Original = Documents.Open("C:\TestA\" & myFile)
Set Copy = Documents.Open("C:\TestB\" & myFile)
Application.CompareDocuments OriginalDocument:=Original, _
RevisedDocument:=Copy, _
Destination:=wdDompareDestinationNew, _
Granularity:=wdGranularityCharLevel, _
CompareFormatting:=False, _
CompareCaseChanges:=False, _
CompareWhitespace:=False, _
CompareTables:=False, _
CompareHeaders:=False, _
CompareFootnotes:=False, _
CompareTextboxes:=True, _
CompareFields:=True, _
CompareComments:=True, _
CompareMoves:=True, _
RevisedAuthor:="", _
IgnoreAllComparisonWarnings:=False
Original.Close SaveChanges:=True
Copy.Close SaveChanges:=True
myFile = Dir()
Wend
End Sub
*** Code End
But how write it without opening Documents? (Documents.open)
And how use Destination:=wdDompareDestinationNew to create a new file? this code will change the original (Test A)
Thanks!
Sorry for my english, i am not native ...
I am new here. I sometimes need to use VBA in Word 2007 (i am not a great programmer) and now i need to write VBA for comparing files in two folders (both includes the same files, one new and second older). I need to automaticaly compare it, and for the best, in third folder create documents with changes (where.
But i cannot write the method Application.CompareDocuments without opening documents (it doesn't work). If i opened dokuments, then it works, but for 700 files it will be very slowly. There is one more complication, these documents are made from external program and when is the document opened in the Word, the Word ask for contacting the database, i must press Esc, then is the document opened (type is *.rtf).
This works:
*** Code Start
Sub porovnani_souboru()
'
' porovnani_souboru Makro
'
'
Dim myFile As String
Dim Original As Document
Dim Copy As Document
myFile = Dir("C:\TestA\*.rtf")
While myFile <> ""
Set Original = Documents.Open("C:\TestA\" & myFile)
Set Copy = Documents.Open("C:\TestB\" & myFile)
Application.CompareDocuments OriginalDocument:=Original, _
RevisedDocument:=Copy, _
Destination:=wdDompareDestinationNew, _
Granularity:=wdGranularityCharLevel, _
CompareFormatting:=False, _
CompareCaseChanges:=False, _
CompareWhitespace:=False, _
CompareTables:=False, _
CompareHeaders:=False, _
CompareFootnotes:=False, _
CompareTextboxes:=True, _
CompareFields:=True, _
CompareComments:=True, _
CompareMoves:=True, _
RevisedAuthor:="", _
IgnoreAllComparisonWarnings:=False
Original.Close SaveChanges:=True
Copy.Close SaveChanges:=True
myFile = Dir()
Wend
End Sub
*** Code End
But how write it without opening Documents? (Documents.open)
And how use Destination:=wdDompareDestinationNew to create a new file? this code will change the original (Test A)
Thanks!
Sorry for my english, i am not native ...