PDA

View Full Version : Macro to higlight repeated words



Maheshdx
09-27-2010, 06:05 AM
Hi
I have started the thread for macros highlighting repeated words.

I have no idea about creating macros. But i use wildcards and create macros. I used "[!a-z]([A-z]{2,} ){2}" and creaded macro to higlight repeated words. But i coudn't create macro for higlighting "David, 1999; David, 1899". The output should be like that mentioned below.

In a document, the macro should find the word which comes with the year and then go to the word next to the year. If both words before and after the year are same, it should highlight both the words. Is is possible?

"There are many differences from a country to (AAAA, 1991; AAAA, 1995; BBB and CCC, 1997) another (BBB and CCC, 1997; AAAA, 1991). There are many differences from a country to another. There are many differences from a country to another (DDD et al., 1997; DDD et al., 1865) regarding institution."

In the first occurence word "AAAA" is same before and after the year. Hence higlighted. Then AAAA,1995 and BBB and CCC different. So, not higlighted. Third occurence same words. Hence higlighted. Clear........

fumei
09-27-2010, 10:12 AM
Please post the example starting text, and what you want to see as final text. Your explanation is not clear enough.

As macropod mentioned in the other thread, to more complicated you make it, the harder it becomes. On first look here, this would be difficult. Not impossible, but difficult, and requires very exactly logic. If I understand correctly:

AAAA, 1991; AAAA, 1995; BBB and CCC, 1997

becomes

AAAA, 1991; AAAA, 1995; BBB and CCC, 1997)

but no other highlights.

DDD et al., 1997; DDD et al., 1865

might look to be highlighted, but is not because of the et al.

Logic (as stated): If both words before and after the year are same

In this case the word before is "et al" and the word after is "DDD"

I realize that, in fact, you likely DO want this example highlighted. However, your logic does not.

Logic (as stated): If both words before and after the year are same

In this case, the word before is "et al" and the word after is "DDD"

Maheshdx
09-28-2010, 02:52 AM
Hi
There are three only occurrence
1 Aaaa, 1998 (one word with year)
2 Aaaa and Bbbbb, 1998 (two words and a year)
3 Aaa et al., 1998 (one word with et al and a year)


I want the macro find the year. Then should go to the words before the year. The word starts with an uppercase letter and in any of the three occurrences mentioned above.
Move to the words after the year. The word starts with an uppercase letter and in any of the three occurrences mentioned above.
If the first selection and the second are same. It should highlight that words.
(Aaaa, 1998; Aaaa and Bbbbb, 1998; Aaa et al., 1998)
(Aaaa, 1998; Aaaa, 1922; Aaaa and Bbbbb, 1998; Aaa et al., 1998; Aaa et al., 1998)

fumei
09-28-2010, 01:44 PM
There are three only occurrence
1 Aaaa, 1998 (one word with year)
2 Aaaa and Bbbbb, 1998 (two words and a year)
3 Aaa et al., 1998 (one word with et al and a year)

I want the macro find the year. Then should go to the words before the year. The word starts with an uppercase letter and in any of the three occurrences mentioned above.


Sorry, but you are incorrect. The word before the year in:

3 Aaa et al., 1998 (one word with et al and a year)

is...."et al". Not "one word with et al. The word before the year is, in fact, not even "et al".

The word before the year is: "," the comma. The word before THAT is...".". The word before THAT is: "al". The word before THAT is: "et"

The "Aaa" is the fifth word before 1998.

"Aaa" is NOT the word before 1998.

fumei
09-28-2010, 01:46 PM
Oh and:

2 Aaaa and Bbbbb, 1998 (two words and a year)

Sorry, but that is NOT "two words and a year".

It is THREE words. Aaaa, and, Bbbb

Maheshdx
09-29-2010, 06:31 AM
Hi
Thanks for reply. I have cleary mentioned that after finding the year, next step will be moving to the word before the year which starts with “upper case letter”. But “et al” does not start with upper case letter. Clear?
(Aaaa et al., 1989)
Here macro will find the year “1989” then finds the words before the year which starts with upper case letter “A”aaa. Leaving “dot” or “comma”, it should find upto the last letter before the year. Here it is “l”.
See also the following occurences:
“Aaaa, 1998”--- here uppercase letter “A” and upto last letter “a” before year.
“Aaa et al., 1998”---- here uppercase letter “A” and upto last letter “l” before year
“Aaaa and Bbbbb, 1998”----- in this case uppercase letter “B” but if “and” comes before the word it should find the word before “and” which starts with upper case letter. So “A” is the starting letter and “b” will be the ending letter”. Fine ha…

Have you got the macro for single word and year. Can I use that and clear you?

fumei
09-29-2010, 10:19 AM
Sorry. but I do not think you are realizing how much work this would be. You have to test each and every word.

"Have you got the macro for single word and year. Can I use that and clear you?"

OK. Good luck.

Sub PainInTheButt()
Dim check
Dim aWord
For Each aWord In ActiveDocument.Range.Words
' test to see if 4 characters long (e.g. 1998) AND
' it is numeric
If Len(aWord) = 4 And _
IsNumeric(aWord) = True Then
MsgBox aWord.Previous
End If
Next
End Sub
I suggest you try this with (Aaaa et al., 1989).

Now how are you going about finding the year? Are you using Find instead? How do you think you are going to work backwards until to get to the UpperCase letter?

Maheshdx
11-23-2010, 06:21 AM
Hi
Is there a code to find words repeated within a parenthesis
e.g. (one two three four one three), here one and three repeated. Those words should be higlighted. Is it possible?