Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-02-2015, 12:58 PM
Bookmaster Bookmaster is offline VBA to solve duplicate words in one line Windows XP VBA to solve duplicate words in one line Office 2003
Novice
VBA to solve duplicate words in one line
 
Join Date: Dec 2009
Posts: 6
Bookmaster is on a distinguished road
Default VBA to solve duplicate words in one line

Hello,



I have a lots of word documents and in any of them I have a lots of lines which finish with paragraph. My problem is that in lines I have duplicate words.

I need VBA to find and delete duplicate words in one line. It has to look just in one line and if it finds duplicate words it has to delete them and to leave just one of them. Then it has to go to next line, to look for duplicate words and delete them,....

Looking forward for any reply.

BM
Reply With Quote
  #2  
Old 02-02-2015, 02:22 PM
macropod's Avatar
macropod macropod is offline VBA to solve duplicate words in one line Windows 7 64bit VBA to solve duplicate words in one line Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

What are your criteria for duplicates? After all, in:
The quick brown fox jumped over a lazy dog. The flat cat ate a brown mouse.
the words 'The', 'a' and 'brown' are all repeated on the same line, but I'd hardly call any of them duplicates.

Also Word doesn't work in lines - it works in paragraphs. That's because what constitutes a line in a multi-line paragraph can vary according to what printer is attached, plus to simple things like changes to margins, etc. Word VBA also doesn't work in grammatical sentences.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 02-02-2015, 11:59 PM
Bookmaster Bookmaster is offline VBA to solve duplicate words in one line Windows XP VBA to solve duplicate words in one line Office 2003
Novice
VBA to solve duplicate words in one line
 
Join Date: Dec 2009
Posts: 6
Bookmaster is on a distinguished road
Default

Hello and thanks for reply.
My lines in word looks like this:

Many years ago many years ago I did nice job - that is one of lines that I have duplicate words.
So I want my line to be Many years ago I did nice job
I am not so familiar with English, but I hope so that will help about my criteria.

BM
Reply With Quote
  #4  
Old 02-03-2015, 01:00 AM
macropod's Avatar
macropod macropod is offline VBA to solve duplicate words in one line Windows 7 64bit VBA to solve duplicate words in one line Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The problem with what you're asking is that there is no reliable way of determining what a duplicate word or phrase is. Even in your example, 'many' is not a literal duplicate of 'Many'. Also, what happens if there are other words between your duplicates, for example:
Many years ago I did many years ago a nice job.
For all anyone except the author knows, the correct expression after duplicate removal might be:
Many years ago I did many a nice job.
or:
Many years ago I did a nice job.
Both are grammatically and linguistically valid.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 02-03-2015, 01:20 AM
Bookmaster Bookmaster is offline VBA to solve duplicate words in one line Windows XP VBA to solve duplicate words in one line Office 2003
Novice
VBA to solve duplicate words in one line
 
Join Date: Dec 2009
Posts: 6
Bookmaster is on a distinguished road
Default

Thanks again for quick reply, but I don't need any word to be moved from its position in line. So if line is "Many many years ago ago I did good job", I just need vba to remove many and ago and to leave line like this "Many years ago I did good job". There is no need for grammar or any other spelling. Just simple remove duplicates in one line.

If that is not possible, thank you again for ur time.

BM
Reply With Quote
  #6  
Old 02-03-2015, 03:31 AM
macropod's Avatar
macropod macropod is offline VBA to solve duplicate words in one line Windows 7 64bit VBA to solve duplicate words in one line Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by Bookmaster View Post
Thanks again for quick reply, but I don't need any word to be moved from its position in line. ... There is no need for grammar or any other spelling. Just simple remove duplicates in one line.
So you really want it to turn:
The quick brown fox jumped over a lazy dog. The flat cat ate a brown mouse.
into:
The quick brown fox jumped over a lazy dog. flat cat ate mouse.
???

This isn't about vba checking spelling or grammar - or about words being moved - it's a question of logic. And, as I said:
Quote:
Even in your example, 'many' is not a literal duplicate of 'Many'.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 02-03-2015, 03:49 AM
Bookmaster Bookmaster is offline VBA to solve duplicate words in one line Windows XP VBA to solve duplicate words in one line Office 2003
Novice
VBA to solve duplicate words in one line
 
Join Date: Dec 2009
Posts: 6
Bookmaster is on a distinguished road
Default

Yes please, I want to have exactly what u wrote. In English language that may look very stupid and funny, but for may language that makes sense.

Looking forward for ur reply
Reply With Quote
  #8  
Old 02-03-2015, 04:30 PM
macropod's Avatar
macropod macropod is offline VBA to solve duplicate words in one line Windows 7 64bit VBA to solve duplicate words in one line Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try the following macro - it doesn't find 'duplicates' where one word uses capitals and the other doesn't, but it should deal with all the rest.
Code:
Sub Demo()
Dim i As Long
Application.ScreenUpdating = False
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "(<[A-Za-z]@>)([!^13]@)<\1>"
    .Replacement.Text = "\1\2"
    .Format = False
    .Forward = True
    .Wrap = wdFindContinue
    .MatchWildcards = True
  End With
  Do While i <> Len(.Text)
    i = Len(.Text)
    .Find.Execute Replace:=wdReplaceAll
  Loop
  With .Find
    .Text = "[ ]{2,}"
    .Replacement.Text = " "
    .Execute Replace:=wdReplaceAll
  End With
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to solve duplicate words in one line Word 2013 words cut at end of line and other decalations Alex.g Word 4 06-20-2022 07:50 PM
VBA to solve duplicate words in one line How to find and delete duplicate words in doc cinvest Word 1 09-29-2014 08:34 PM
Can anyone solve this problem? ChrisHoppyBot Office 0 02-20-2013 01:08 AM
Creating different spacing for words on the same line Jenjen80 Word 1 08-12-2010 05:52 AM
please help me to solve this issue...... middo1022 PowerPoint 0 08-28-2009 04:47 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:17 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft