Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can QTP compare two MS word documents
#3
Solved: 10 Years, 10 Months, 1 Week ago
Find the below code to Comapare Two word documents.

Code:
F_Path_1="D:\Compare\Document1.rtf"
F_Path_2="D:\Compare\Document2.rtf"

Public Function CompareFiles (F_Path_1, F_Path_2)

Dim FS, first_file, second_file
Set FS = CreateObject("Scripting.FileSystemObject")

  'Function will simply exit if the size of both files being
' compared is not equal

If FS.GetFile(F_Path_1).Size <> FS.GetFile(F_Path_2).Size Then
CompareFiles = True
Exit Function
End If

  'OpenAsTextStream Method: Opens a specified file and returns
'a TextStream object that can be used to read from, write to,
'or append to the file.

Set first_file = FS.GetFile(F_Path_1).OpenAsTextStream(1, 0)
Set second_file = FS.GetFile(F_Path_2).OpenAsTextStream(1, 0)

CompareFiles = False

  'AtEndOfStream Property: Read-only property that returns True
'if the file pointer is at the end of a TextStream file; False
'if it is not.

  Do While first_file.AtEndOfStream = False
      
  'The Read method reads a specified number of characters from
'a TextStream file

Str1 = first_file.Read(1000)
Str2 = second_file.Read(1000)

  'The StrComp function compares two strings and returns 0 if
'the strings are equal

CompareFiles = StrComp(Str1, Str2, 0)
  If CompareFiles <> 0 Then
   CompareFiles = True
   Exit Do
  End If
Loop

first_file.Close()
second_file.Close()
End Function

File1 =inputbox ("Enter first file nam")
File2 = inputbox ("Enter second file name")

If CompareFiles(File1, File2) = False Then
MsgBox File1 & " and " & File2 & " " &  "are identical."
Else
MsgBox File1 & " and " & File2 & " " &  "are NOT identical."
End If

Regards,

Reply


Messages In This Thread
Can QTP compare two MS word documents - by Yogini - 10-28-2008, 12:06 PM
RE: Can QTP compare two MS word documents - by qtpdeepak - 09-10-2009, 04:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  UFT Word automation wannel 1 2,193 10-31-2016, 06:59 PM
Last Post: wannel
  Compare WebTable Elements saraiado 1 2,466 06-11-2015, 06:54 PM
Last Post: venkatesh9032
  How to compare two binary values Naresh 0 2,214 09-09-2014, 05:06 PM
Last Post: Naresh
  Can QTP AOM identify word documents that are already opened anil2u 2 4,105 09-05-2013, 12:45 PM
Last Post: anil2u
  how to compare excel with datatatble diya 4 5,274 12-04-2012, 05:39 AM
Last Post: diya

Forum Jump:


Users browsing this thread: 1 Guest(s)