SEARCH

The How-To Geek Forums Have Migrated to Discourse

How-To Geek Forums / Microsoft Office

removing duplicate words in a microsft word document

(2 posts)
  • Started 1 year ago by jjrodrigues
  • Latest reply from moreeg
  • Topic Viewed 1120 times

jjrodrigues
Posts: 1

ANYBODY CAN HELP ME? - IF YOU DO NOT KNOW PLS DO NOT WRITE GUESSES.
I HAVE INSTALLED THE FOLLWING MACRO IN MY COMPUTER............
=========================================================='
'Dim AmountMoved As Long
Dim myRange As Range
Selection.WholeStory
Selection.Sort ExcludeHeader:=False, FieldNumber:="Paragraphs", _
SortFieldType:=wdSortFieldAlphanumeric, SortOrder:=wdSortOrderAscending, _
FieldNumber2:="", SortFieldType2:=wdSortFieldAlphanumeric, SortOrder2:= _
wdSortOrderAscending, FieldNumber3:="", SortFieldType3:= _
wdSortFieldAlphanumeric, SortOrder3:=wdSortOrderAscending, Separator:= _
wdSortSeparateByTabs, SortColumn:=False, CaseSensitive:=False, LanguageID _
:=wdEnglishUS, SubFieldNumber:="Paragraphs", SubFieldNumber2:= _
"Paragraphs", SubFieldNumber3:="Paragraphs"
'start with first paragraph and extend range down to second
Set myRange = ActiveDocument.Paragraphs(1).Range
AmountMoved = myRange.MoveEnd(unit:=wdParagraph, Count:=1)
'loop until there are no more paragraphs to check
Do While AmountMoved > 0
'if two paragraphs are identical, delete second one
'and add the one after that to myRange so it can be checked
If myRange.Paragraphs(1).Range.Text = _
myRange.Paragraphs(2).Range.Text Then
myRange.Paragraphs(2).Range.Delete
AmountMoved = myRange.MoveEnd(unit:=wdParagraph, Count:=1)
Else
'if two paragraphs aren't identical, add the one after
'that to my range, so it can be checked, and drop the first one,
'since it is no longer of interest.
AmountMoved = myRange.MoveEnd(unit:=wdParagraph, Count:=1)
myRange.MoveStart unit:=wdParagraph, Count:=1
End If
Loop
MsgBox ("end")
End Sub
==========================================
WHILE RUNNING I AM GETTING THE FOLLOWING MESSAGE-- ONLY COMMENTS MAY APPEAR AFTER END SUB , END FUNCTION, OR END...I CANNOT FIGURE OU WHAT IT IS...... COULD IT BE THAT I PASTED THE MACRO IN THE WRONG PLACE --THAT IS....AFTER I HAD sub general ---general macro--end sub --- why else could it not run?

Posted 1 year ago
Top
 
moreeg
moreeg
Posts: 842

I copied your code and pasted it into a macro and added this line at the top

sub test()

It worked fine.

Based on the information you provided I could only guess as to why it didn't work for you.

Posted 1 year ago
Top
 



Topic Closed

This topic has been closed to new replies.