So I'm trying to write a Word macro that compares just the first paragraph of two files with identical contents. (One is the active file, one is a specified "Reference File.") For some reason, the two ranges I'm using to store the contents keep coming up as not equal, even though using Documents.Compare to check the two files comes up with no differences.
Checking the variables as I step through also makes it seem as though the two ranges' contents are identical at the time of comparison. Does anyone have any idea of why this might be happening??
Apologies in advance for inconsistent variable naming schemes.
Sub Test_Comparison()
Dim WorkingDoc As Document
Dim formatRef As Document
Dim rngDoc As Range
Dim refRange As Range
Dim MacroViable As Boolean
Set WorkingDoc = Documents(ActiveDocument)
Set formatRef = Application.Documents.Open("[Reference FilePath]\ReferenceFile.docx", ReadOnly:=True, Visible:=False)
Set rngDoc = Documents(WorkingDoc).Paragraphs(1).Range
Set refRange = formatRef.Paragraphs(1).Range
If rngDoc.IsEqual(Range:=refRange) Then 'This is the bit not working. The contents of the variables seems identical. What gives??
MacroViable = True
End If
Documents("ReferenceFile.docx").Close
End Sub
I also tried just setting the two ranges equal, as so:
If refRange = rngDoc Then
MacroViable = True
End If