Class Version (Word VBA)

The class Version represents a single version of a document. The Version object is a member of the Versions collection. The Versions collection includes all the versions of the specified document. To use a Version class variable it first needs to be instantiated, for example

Comment

Returns the comment associated with the specified version of a document.


If ActiveDocument.Versions.Count >= 1 Then 
 MsgBox Prompt:=ActiveDocument.Versions(1).Comment, _ 
 Title:="First Version Comment" 
End If

Date

The date and time that the document version was saved.


Dim docActive As Document 
 
Set docActive = ActiveDocument 

Delete

Deletes the specified version.


Dim vrs As Version: Set vrs =  
vrs.Delete

Index

Returns a Long that represents the position of an item in a collection.


Dim vrs As Version: Set vrs =  
Dim lngIndex As Long
lngIndex = vrs.Index

Open

Opens the specified version of a document. Returns a Document object representing the opened document.


Sub OpenVersion() 
 Dim mydoc As Document 
 Set mydoc = Documents.Open("C:\MyFiles\Report.doc") 
 If mydoc.Versions.Count > 0 Then 
 mydoc.Versions(mydoc.Versions.Count).Open 
 Else 
 MsgBox "There are no saved versions for this document." 
 End If 
End Sub

SavedBy

Returns the name of the user who saved the specified version of the document.


If ActiveDocument.Versions.Count >= 1 Then 
 MsgBox ActiveDocument.Versions(1).SavedBy 
End If