none
Compare 2 documents including the header and footer (VB Script) RRS feed

  • Question

  • Hi,

    I tried comparing 2 documents. Only the contents are compared successfully.

     set oWord = createobject("Word.Application")
     Set oDoc1=oWord.Documents.Open(Doc1)
     Set oDoc2=oWord.Documents.Open(Doc2)
     Set Dcomp=oWord.CompareDocuments(oDoc1,oDoc2)
     changesCount= Dcomp.Revisions.count

    But I have some documents where there are headers, footers, text/images in headers etc.,

    But the code is not verifying the text/images in header or footer.. how to compare the whole word document

    Thanks

    Mohan 

    Friday, June 5, 2015 4:58 PM

Answers

  • Hi Mohan,

    >>But the code is not verifying the text/images in header or footer.. how to compare the whole word document

    In my option, the "Dcomp.Revisions.count" only contains the revisions in the document body, if you want to get the revisions of the header and footer, I suggest you get the revisions from the header range and footer range, a simple code as below:

    Sub CompareDoc()
    Dim dcomp As Document
      Set oWord = GetObject(, "Word.Application")
      Set oDoc1 = oWord.Documents.Open("D:\OfficeDev\Word\201506\Doc1.docx")
      Set oDoc2 = oWord.Documents.Open("D:\OfficeDev\Word\201506\Doc2.docx")
      Set dcomp = oWord.CompareDocuments(oDoc1, oDoc2)
      changesCount = dcomp.Revisions.Count
      changeHeader = dcomp.Sections(1).Headers(wdHeaderFooterPrimary).Range.Revisions.Count
      changeFooter = dcomp.Sections(1).Footers(wdHeaderFooterPrimary).Range.Revisions.Count
    End Sub

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Marked as answer by JS Mohan Thursday, June 11, 2015 3:27 PM
    Tuesday, June 9, 2015 11:43 AM

All replies

  • I find this demo from other post, hope helpful.

    Compare two Word Documents or PDF Files in C# and Display Diffs in ASP.NET.

    In it's introduction it says "The library recognizes changes in text, tables, headers, footers, footnotes and even styles formatting. "  

    --------------------------------------------------------------------

    Free .NET WORD library supporting editing and conversion of Word files.


    Tuesday, June 9, 2015 6:55 AM
  • Hi Mohan,

    >>But the code is not verifying the text/images in header or footer.. how to compare the whole word document

    In my option, the "Dcomp.Revisions.count" only contains the revisions in the document body, if you want to get the revisions of the header and footer, I suggest you get the revisions from the header range and footer range, a simple code as below:

    Sub CompareDoc()
    Dim dcomp As Document
      Set oWord = GetObject(, "Word.Application")
      Set oDoc1 = oWord.Documents.Open("D:\OfficeDev\Word\201506\Doc1.docx")
      Set oDoc2 = oWord.Documents.Open("D:\OfficeDev\Word\201506\Doc2.docx")
      Set dcomp = oWord.CompareDocuments(oDoc1, oDoc2)
      changesCount = dcomp.Revisions.Count
      changeHeader = dcomp.Sections(1).Headers(wdHeaderFooterPrimary).Range.Revisions.Count
      changeFooter = dcomp.Sections(1).Footers(wdHeaderFooterPrimary).Range.Revisions.Count
    End Sub

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Marked as answer by JS Mohan Thursday, June 11, 2015 3:27 PM
    Tuesday, June 9, 2015 11:43 AM
  • Thanks Edward, its working
    Thursday, June 11, 2015 3:27 PM