Forum Discussion
how can I undo a macro in Word? - SOLVED :)
- Oct 14, 2019
nata7 As I mentioned briefly before, a macro can examine the date on which a tracked change was made, and decide whether to reject that change. The following macro asks you to enter the date that the changes were made. It then looks at each tracked change (all 3000 of them). If the change's date matches the date you entered, and if the font color of that change is red, then the macro rejects that change. Otherwise the change is ignored. The macro counts the number of changes it rejected, and displays the number in the status bar at the bottom of the Word window and in a message box when the macro finishes.
Sub RejectTimedRevision()
Dim objRev As Revision
Dim objDate As Date
Dim strDate As String
Dim lngCount As Long
GetDate:
strDate = InputBox(prompt:="Enter date of changes:", _
Title:="Reject Changes from Specified Date")
If strDate = "" Then Exit Sub
If IsDate(strDate) Then
objDate = CDate(strDate)
Else
MsgBox strDate & " is not a valid date. Try again."
GoTo GetDate
End If
For Each objRev In ActiveDocument.Revisions
If InStr(objRev.Date, objDate) And _
(objRev.Range.Font.ColorIndex = wdRed) Then
objRev.Reject
lngCount = lngCount + 1
StatusBar = CStr(lngCount) & " revisions rejected"
End If
Next objRev
MsgBox CStr(lngCount) & " revisions rejected"
End Sub
Thank youJay Freedman .
I have over 3000 changes in the Reviewing Pane. I am guessing almost 1000 of them are the problematic changes of long sentences to red color. So, it is really too much work also to look through all the 3000+ changes.
Is it possible to filter all the tracked changes according to date? This way at least I wouldnt have to go through all changes since I would have all the problematic ones listed one after the other.
nata7 As I mentioned briefly before, a macro can examine the date on which a tracked change was made, and decide whether to reject that change. The following macro asks you to enter the date that the changes were made. It then looks at each tracked change (all 3000 of them). If the change's date matches the date you entered, and if the font color of that change is red, then the macro rejects that change. Otherwise the change is ignored. The macro counts the number of changes it rejected, and displays the number in the status bar at the bottom of the Word window and in a message box when the macro finishes.
Sub RejectTimedRevision()
Dim objRev As Revision
Dim objDate As Date
Dim strDate As String
Dim lngCount As Long
GetDate:
strDate = InputBox(prompt:="Enter date of changes:", _
Title:="Reject Changes from Specified Date")
If strDate = "" Then Exit Sub
If IsDate(strDate) Then
objDate = CDate(strDate)
Else
MsgBox strDate & " is not a valid date. Try again."
GoTo GetDate
End If
For Each objRev In ActiveDocument.Revisions
If InStr(objRev.Date, objDate) And _
(objRev.Range.Font.ColorIndex = wdRed) Then
objRev.Reject
lngCount = lngCount + 1
StatusBar = CStr(lngCount) & " revisions rejected"
End If
Next objRev
MsgBox CStr(lngCount) & " revisions rejected"
End Sub
- nata7Oct 15, 2019Copper Contributor
Thank youJay Freedman , you are my saviour here! You were right, your macro worked with the date form you suggested.
If someone is reading this who is also in similar predicament, let there be no confusion, this solution works but only if you had "Track Changes" on.
Bless you!
- Jay FreedmanOct 15, 2019MVP
nata7 VBA is a bit unpredictable about the way it interprets dates entered as strings. It depends mostly on your Windows settings, particularly the Short Date format. I suspect that when you entered 10/12/2013 (as month/day/year, which is the default for US English), the program interpreted it in day/month/year format as 10 December 2019.
Try running the macro again and enter the date as 12/10/2019 to see whether it works.
- nata7Oct 14, 2019Copper Contributor
Thank youJay Freedman , you are so kind, I really appreciate it.
I created and run your macro. I entered the date and in the end the message popped up: "0 revisions were rejected" - How come? Could it be possible that there is some error in the macro or in something else - maybe in the date form? I entered the date 10/12/2019 - because this is how dates are displayed in the Review pane of my Word document, but overhere we write dates 12.10.2019.
Or, could the problem be that I did it in a copy of that document (to test it if it works)? Since my first experiment with macros turned very bad, I am now very cautious of using it, so I made a copy of my manuscript and run your macro there. Must I do it directly in the original document? In the copy are all the changes recorded in the Review pane and could be accepted or rejected, but those changes were not actually made in that copy (they were made in the original document).