bradyboyy88
Well-known Member
- Joined
- Feb 25, 2015
- Messages
- 562
I am not able to test the code at the moment but I was curious if anyone knows if the following code would delete all comments in a word document from excel vba. The line which has me worried is Set oComments = WordApp.WordDoc.Comments. I am not sure if that is the correct way to set the oComment object variable or if its even allowed. I am also curious if WordApp.WordDoc.Revisions.AcceptAll is the appropriate syntax.
Code:
Sub FinalizeWordDoc()
'Open Word Doc and replace standard language
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
Dim n As Long
Dim oComments As Comments
Set WordApp = CreateObject("Word.Application")
Set WordDoc = WordApp.Documents.Open("c/blah blah.docx")
WordDoc.Visible=1
Set oComments = WordApp.WordDoc.Comments
For n = oComments.Count To 1 Step -1
oComments(n).Delete
Next 'n
'Remove track changes
WordApp.WordDoc.Revisions.AcceptAll
Set oComments = Nothing
Set WordDoc = Nothing
Set WordApp = Nothing
End Sub
Last edited: