PDA

View Full Version : compare words



ilyaskazi
11-16-2005, 12:57 AM
i m newbie in word-vba here and this is my first post:

I need to compare word of my activedocument (Doc1.doc) with another opened document (Doc2.doc)

If any words differ in Doc2 then give font color as red to that word in Doc2.

Kindly :help

TonyJollans
11-16-2005, 06:43 AM
Hi ilyaskazi,

If you want to compare two documents you can use Tools > Compare and Merge.

If you want to do something else can you give a little more detail please.

ilyaskazi
11-16-2005, 09:55 PM
Tools > Compare and Merge .... is not enough.

My document contains header and footer, tables and text boxes which are not compared by the above in-built tool. Also it is comparing only lines and not words in line.

I have tried using Microsoft's code:

Sub CompareWordFile_WithMicrosoft()
ActiveDocument.Compare Name:= _
"C:\Documents and Settings\Ilyas\My Documents\Project_Word\Doc2.doc", _
CompareTarget:=wdCompareTargetNew
End Sub

... this is almost to my requirements, but cannot generate report which i need to maintain in new document specifying line number and column number in which error occured. :dunno

TonyJollans
11-17-2005, 01:39 AM
Word's compare does not work on a line basis - it can, and does, identify words changed within a line. If it flags a line as changed it's because, by its reckoning, the whole line has changed.

To write something of your own is a major undertaking. I would strongly recommend that you try and find a way of working with what Word gives you. If you really can't do that then your best bet is to see if there are any third party products which might meet your needs (I am not aware of any). It will cost thousands to get bespoke code for this.

fumei
11-17-2005, 08:53 AM
You would have to really spec out things. You mention column number. Are you talking about table columns, or columns in the document? Why do you need line numbers if you are making a visual identifier with the red font?

Why are you doing this anyway? What is the actual purpose? Are you trying to do this on a individual word/compare basis? As in, take the first word and check the other document for ANY matches? Or is it first word match to first word; second word match to second word etc etc? Do you need to check if the word count is equal? If it is NOT equal - what are you supposed to do?

What precisely do you mean by "error"?

Tony is right in that it could be done, but it would not be trivial to do so.

ilyaskazi
11-17-2005, 11:58 PM
Thankyou Tony, for giving several options.

As far as I understand, MS-Word's compare as per sentence and not line. If it founds any character/word missing in complete sentence, it shows the differences in comment and well as in Review Window in New Document.

Gerry, as I said in post #3, document may contain tables, text boxes etc,etc. In short everything which can be in word document. I m working in the field of Airlines, from where we receive some contract files in word. We receive documents from various airlines with their unique format. Every airline has their own fashion. After receiving this document, we collect the information contained in it and populate the fields in our Excel-Template to upload database for e-ticketing.

Our problem: Some times we get revised contract file by Airline company after few days to re-upload database with changes immediately. And this is not easy stuff to find out what really changes are in whole document in compare to original document.

So actually here I needed some tool to find out the differences between my original and revised document.

I need to find out the differences in line rather than in sentences.
For Eg: In first line count words of both documents. Compare that line with word to word until it reaches the minimum counted words of any document. Show the 'error' mark as font.color=wdRed in document-2 and in new document write the line number and its column number, where error occured. So on for all lines.

I understand it is not an easy task. But I have to give a start.

fumei
11-18-2005, 04:44 AM
You did not answer the question. What are the "column numbers" you mention?

Of what use is the line number? WHY do you need the line number? WHY is the line number helpful to what you are trying to do?

You mention error mark. I have absolutely no idea what you mean by error mark. What mark? There is no "error", so is there a mark. Yes, there may be a difference of text. This is not an error. So what, exactly, is changed to red font?

DOC1: "There is a flight leaving at noon."
DOC2: "There is a flight leaving at 6:00 AM."

Is 6:00 AM now red? Is noon now red? You state you want to give the different word in doc2 red font. OK.

DOC1: "There is a flight leaving at noon."
DOC2: "Bleech budda dufthy negt."

All the words are different. Does that mean the entire sentence is now red?

DOC1: "There is a flight leaving at noon."
DOC2: "The quick brown fox jumped over whatever was in the way as that is
what quick brown foxes do."

Suppose the sentence goes into the next "line". Are you saying that the line is so important, that:

The quick brown fox jumped over whatever was in the way as that is - is now red, but,

what quick brown foxes do. - is not.

DOC3: you mention "new" document...is this a third document? The other ones are already there, so "new" means - well, new. So there is a third document?

You mention "minimum counted words" in any document. Uh, this would always be zero. The MINIMUM counted words of any document is 0 - no words at all. So, again, I have no idea what you mean by this.

Like I stated, you need to specify precisely what you want things to do. Every single step, and make little steps. So far, you are much too fuzzy for anything practical.

Good luck.

TonyJollans
11-18-2005, 05:34 AM
Hi ilyaskazi,

You are probably correct in what you say about Word's compare; I, not for the first time, jumped to conclusions based on the results it gives. However, what differences does it not identify? If you can say what they are and - and this is important - the documents are always in the same format so that it is only textual content that has changed then it might be possible to write some code which compared tables, textboxes etc. If the documents could have significant structural differences then it will require significant work.

I guess what I'm really saying is that it depends on how clearly the possible changes can be specified. A full blown compare is out of the question but if you are looking for, say, a table with a different number of rows (providing the documents have the same number of tables) it might be possible. Whatever you do will have limitations so it is important to specify precisely what you're looking for - and what to do should the documents not be in the format expected.

fumei
11-18-2005, 11:15 AM
In other words...describe in detail precisely what you want to happen, and under what circumstances.