Forum Discussion

nata7's avatar
nata7
Copper Contributor
Oct 12, 2019

how can I undo a macro in Word? - SOLVED :)

Hi, how can I undo a macro in Word? I added a code to mark long sentences and I run it.This is the code: Sub Mark_Long()     Dim iMyCount As Integer     Dim iWords As Integer       If Not Act...
  • Jay Freedman's avatar
    Jay Freedman
    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

Resources