Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
[email protected] o0aiur0o@gmail.com is offline
external usenet poster
 
Posts: 1
Default Macro can't find the end of document in word 2016 (Requested Memberof the Collection Does Not Exist)

I have a macro that can find all duplicate word pairs, highlight them, then play a sound to notify me as follow:

Sub CheckEnglishAndTypos()
'Go to the beginning to start the search
Selection.HomeKey Unit:=wdStory

Selection.Paragraphs(1).Range.Select
Selection.Find.Highlight = False
Selection.Find.Replacement.Highlight = True
With Selection.Find
.Text = "(*) \1"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

Do Until ActiveDocument.Bookmarks("\Sel").Range.End = ActiveDocument.Bookmarks("\EndOfDoc").Range.End
'Loop the search till the end
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Paragraphs(1).Range.Select
With Selection.Find
.Text = "(*) \1"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Loop
' Searching the remaning (till the end of document)
Exit Sub
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
PlayTheSound "Task Completed.wav"
End Sub

This thing works like a charm on short documents, but for anything over 100 pages, it gives me the "Requested Member of the Collection Does Not Exist".

In debug mode, the line corresponds to the error is "Do Until ActiveDocument.Bookmarks("\Sel").Range.End = ActiveDocument.Bookmarks("\EndOfDoc").Range.End".

When I checked over the test document, apparently the thing did highlight everything to the end. But for some bloody reason, it couldn't find where the document end. So the macro just stopped, and no sound was played.

Is there anyway to fix it?
Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Word 2016] Style lost on copy&paste Cristiano Microsoft Word Help 1 March 2nd 16 01:29 PM
Conversion of Microsoft Word VBA from windows version to Office 2016 for Mac. rimjhim Microsoft Word Help 0 February 3rd 16 06:11 PM
'addrow' VB macro error: requested member of collection does not e RDS Tables 4 January 14th 08 03:30 PM
In Word symbol for a 1/16 of inche does not exist,where to find? Claude Microsoft Word Help 2 January 17th 06 06:52 PM
Error 5941 - The requested member of the collection does not exsis Melisa Microsoft Word Help 3 July 13th 05 03:56 PM


All times are GMT +1. The time now is 02:56 PM.

Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
Copyright 2004-2023 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"