In VBA macro, accessing any comment via "For Each... "causes Run-time error 5825

John Austin 0 Reputation points
2024-05-23T10:49:26.62+00:00

VBA has a bug in 2024 versions of Word. Anytime I try to access a comment in a macro using "For Each...", I get a Run-time error 5825 "Object has been deleted". This bug occurs on recent versions of Word on Mac, e.g. 16.85, but not on older versions, e.g. 16.77). "For Each" continues to work for other collections (e.g. Fields)

E.g. a simple test macro, run on any doc containing one or more comments, fails:

Sub testcomm()
For Each comm In ActiveDocument.Comments
x = comm.Scope
Next
End Sub

I found a workaround: replace the above macro with

Sub testcomm2()
For cntr = 1 To ActiveDocument.Comments.Count
x = ActiveDocument.Comments(cntr).Scope
Next
End Sub

Office
Office
A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.
1,400 questions
0 comments No comments
{count} votes