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
Hi,
Unfortunately, the commands that applied through a VBA code cannot be undone!
So, you have to write a second macro to search for the same sentences and remove their colors!
Regards
MySent.Font.Color = wdColorRed
with
MySent.Font.Color = wdColorAutomatic
- nata7Oct 14, 2019Copper Contributor
Thank youJay Freedman . Before I do it I wanted to make sure something and ask you: when I do that, will the color than turn black or will it turn to the previous color?
In my manuscript I have many paragraphs in different colors (with editing each color tells me something - different colors for different editing categories), so now when all the long sentences turned red, I need them to turn to the previous colors, so that I know to which category each edited sentence belongs to.
I really appreciate your help, it means a lot to me, so bless you 🙂
- Jay FreedmanOct 14, 2019Brass ContributorUnfortunately, Word doesn't store any information about the colors those sentences had before you ran the first macro, so there is no programmable way to restore them. The best way now is to write a macro that locates each long sentence, and displays a list of colors for you to choose the one you want to apply. You would have to know which category each sentence belongs to. The best way to know that is to have a backup copy of the document from before the original macro ran, to which you could refer.
- nata7Oct 14, 2019Copper Contributor
Thank youJay Freedman but I don't know how to write such macro and it would be too much work because we are talking about almost 1000 sentences.
If I understood your suggestion correctly, I could then without bothering with macro go from one sentence to another and change color, but this is exactly what I want to avoid as it is to much time-consuming and tedious work.
Another problem is that I had the option to track changes turned on and now all those sentences are marked as changed, although nothing is changed in them, so the editor will be forced to look into them although nothing is there to look. A horrible situation as it requires too much extra work, which is why I am trying to find a solution.
Since I had "Track Changes" on, is there a way to simply discard the changes made that hour or day?