Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-31-2023, 06:29 AM
greenwood45 greenwood45 is offline Error 5852 - Requested object not available (highlight tracked changes macro) Mac OS X Error 5852 - Requested object not available (highlight tracked changes macro) Office 2021
Novice
Error 5852 - Requested object not available (highlight tracked changes macro)
 
Join Date: Oct 2023
Posts: 1
greenwood45 is on a distinguished road
Angry Error 5852 - Requested object not available (highlight tracked changes macro)

Hello all,

I am new to using macros in Microsoft word but am familiarizing myself with it.

I want to use a macro to automatically approve all 'tracked changes', and highlight what was changed. Basically, changing 'track changes' to highlights.

Here's the macro I used:

Sub AcceptChangesAndHighlight()
Dim rev As Revision
Dim rng As Range

For Each rev In ActiveDocument.Revisions
Set rng = rev.Range
rng.Revisions.AcceptAll
rng.HighlightColorIndex = wdPink ' Replace 'wdPink' with the appropriate color index
Next rev
End Sub

It worked in most documents but for some reason, this larger doc I'm trying to use it on (18 pages) I keep getting the following error:

Run-time error '5852': Requested object is not available.

When I click 'Debug', it highlights the line: Set rng = rev.Range


As I said, I'm a beginner to this macro stuff but this has been driving me crazy. I feel like I've tried everything I can think of. I tried other macros as well - I tried this one, which someone posted in another forum:

Sub AcceptChangesAlt()


Dim tempState As Boolean
tempState = ActiveDocument.TrackRevisions

ActiveDocument.TrackRevisions = False
Dim index As Long
Dim changeRange As Range

For index = ActiveDocument.Revisions.count To 1 Step -1
Set changeRange = ActiveDocument.Content
changeRange.Start = ActiveDocument.Revisions(index).Range.Start
changeRange.End = ActiveDocument.Revisions(index).Range.End

changeRange.Revisions.AcceptAll
changeRange.Font.Color = 12611584 ' Set font color (change as needed)
Next

ActiveDocument.TrackRevisions = tempState
End Sub


When I use that one, I get the same error, only this time it highlights:

changeRange.Start = ActiveDocument.Revisions(index).Range.Start

Finally, I tried using this macro:


Sub accept_changes()
tempState = ActiveDocument.TrackRevisions

ActiveDocument.TrackRevisions = False
Dim index As Long, Change As Range
For index = ActiveDocument.Revisions.Count To 1 Step -1
Set Change = ActiveDocument.Revisions(index).Range
Change.Revisions.AcceptAll
Change.Font.Color = 12611584
Next

ActiveDocument.TrackRevisions = tempState
End Sub


And I get the same error. Now, it highlights:
Set Change = ActiveDocument.Revisions(index).Range

I'd really appreciate any help here. I have no idea how to go forward to get this macro to work - you all are my last hope!

P.S. I've heard of people talking about a plugin called Zotero that can cause this error with macros. I don't have that plugin.

Thanks in advance for any help!
Reply With Quote
  #2  
Old 10-31-2023, 07:20 PM
Guessed's Avatar
Guessed Guessed is offline Error 5852 - Requested object not available (highlight tracked changes macro) Windows 10 Error 5852 - Requested object not available (highlight tracked changes macro) Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Without seeing your document it is hard to predict why you are having this problem in some docs but not others. Based on the line throwing the code I would assume that the revision is in a 'range' that can't be defined for some reason.

A quick fix and dirty fix would be to tell your macro to ignore errors by adding a line at the top of the code which says
On Error Resume Next

We could ask why a particular range is causing the error. We could step through the code and see which Revision is not able to define a range. Could it be in a header/footer, text box, footnote, endnote for instance? However the problem may be something else entirely...

If the revision is to delete text AND you accept that revision, what exactly do you think would be highlighted? And it is a general problem if you are looping through a collection if you are removing collection items as you go - this is why you might see code that steps backwards through numbered items.

So maybe you need to think about what exactly it is you want the macro to do and we can suggest some alternative code to achieve that aim. Tracked Revisions have a type that could provide guidance eg
Addition = Accept and highlight
Deletion = Reject and show as strikethrough
Format Change = Accept and highlight as another colour
Moved??

Maybe start by trying the code on these threads https://www.msofficeforums.com/word-...tain-font.html
https://www.msofficeforums.com/word/...-document.html
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply

Tags
macro edit, macro error, macros in word



Similar Threads
Thread Thread Starter Forum Replies Last Post
Error 5852 when stepping through revisions kae0088 Word VBA 4 07-07-2023 02:55 AM
Run-Time error 5941 The Requested member of the collection does not exist , Please help chulupa89 Word VBA 0 03-20-2023 03:07 PM
PLEASE HELP: Run-time error '5941', The requested member of the collection does not exist newb Word VBA 4 06-03-2021 05:11 PM
Error 5852 - Requested object not available (highlight tracked changes macro) vba error (object required) for highlight vowels gsrikanth Word VBA 1 04-22-2012 08:55 PM
Error 5852 - Requested object not available (highlight tracked changes macro) vba error (object required) for highlight vowels gsrikanth Excel Programming 1 04-18-2012 01:06 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:58 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