Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUse VBA macros to accept revisions in a Word document between two dates
DescriptionThis example shows how to use VBA macros to accept revisions in a Word document between two dates.
Keywordscode, format, Word, VBA
CategoriesOffice, Strings
 
The AcceptRevisions subroutine displays a custom dialog (see the download example document) to prompt the user for a start and end date. It then examines each revision and accepts those between the two dates.
 
' Accept all revisions between two dates.
Public Sub AcceptRevisions()
Dim start_date As Date
Dim end_date As Date
Dim dlg As dlgAcceptRevisions
Dim rev As Revision
Dim i As Integer

    ' Get the dates.
    start_date = _
        ActiveDocument.BuiltInDocumentProperties("Creation " & _
        "Date")
    end_date = Now
    If dlgAcceptRevisions.ShowDialog(start_date, end_date) _
        = vbOK Then
        ' Accept revisions between the dates.
        On Error Resume Next
        For Each rev In ActiveDocument.Revisions
            If rev.Date >= start_date And rev.Date <= _
                 end_date Then
            rev.Accept
        Next rev
    End If
End Sub
 
The following code shows how the dlgAcceptRevisions dialog works.
 
Private m_Canceled As Boolean

' Display the dialog. Return vbOK if the user clicks OK.
Public Function ShowDialog(ByRef start_date As Date, ByRef _
    end_date As Date) As VbMsgBoxResult
    txtStartDate.Text = Format$(start_date)
    txtEndDate.Text = Format$(end_date)
    m_Canceled = True

    Me.Show vbModal

    If m_Canceled Then
        ShowDialog = vbCancel
    Else
        start_date = CDate(txtStartDate.Text)
        end_date = CDate(txtEndDate.Text)
        ShowDialog = vbOK
    End If
End Function

Private Sub cmdOk_Click()
    m_Canceled = False
    Me.Hide
End Sub

Private Sub cmdCancel_Click()
    Me.Hide
End Sub
 
For more information on programming the Microsoft Office applications with VBA code, see my book Microsoft Office Programming: A Guide for Experienced Developers.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated