PDA

View Full Version : Obtain version number of SharePoint document



Marcster
06-10-2010, 11:21 AM
Hi People,

I have code that connects to a SharePoint document Library and
lists on worksheet all the documents found in that library.

This is done by doing a Web Query.

What I would like to do is, also display in a column the version number
of the latest document held in the library. The same shown by View History
in SharePoint.

Is this possible?.

Or if the version number was held inside the document itself, say in a
Custom Property, display that in the Excel list.

Does anyone know how to display the version number in the SharePoint
library itself?. If this is possible, then getting the version number in
the Excel extract is possible by doing the Web Query.

Thanks,

kadoyla
07-16-2012, 07:29 AM
I'm not sure if it is possible to show in the Sharepoint view, but I am doing some reporting that needs me to show information about the versions.
All the docs I am looking at are Word 2010. The way I have done it is to get the document name from the folder the library sits in, and then generate a URL string, and open the document using the URL. (I Referenced Microsoft Word 14.0 Object Library)


Sub VersionQuery()
Dim objFSO As Object
Dim objFolder As Object
Dim ObjFile As Object
Dim pth As String
Dim FileNme As String
Dim Nm1 As Integer
Dim Nm2 As Integer
Dim viRow As Integer
Dim dlvVersions As Office.DocumentLibraryVersions
Dim dlvVersion As Office.DocumentLibraryVersion
Dim stExtension As String
Dim wdApp As Word.Application, wdDoc As Word.Document
Set wdApp = CreateObject("Word.Application")
wdApp.Visible = True
viRow = 1
Application.ScreenUpdating = False
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("//YOUR/SHAREPOINT/FOLDER/PATH/")
pth = "//YOUR/SHAREPOINT/SITE/URL/"
For Each ObjFile In objFolder.Files
Nm1 = Len("//YOUR/FOLDER/PATH/")
Nm2 = Len(ObjFile) - Nm1
FileNme = Right(ObjFile, Nm2)

Set wdDoc = wdApp.Documents.Open(pth & FileNme)
wdDoc.Application.Visible = True
Set dlvVersions = wdDoc.DocumentLibraryVersions
If dlvVersions.IsVersioningEnabled = True Then

msgbox dlvVersions.Count
End If

wdDoc.Close False
Next ObjFile
wdApp.Documents.Close False
End Sub


There are various other properties you can return, and when I list the dlvVersion.index it goes through them from top to bottom, so you may need to play around with how you list them but if it just the latest version you are looking at then .count should cover your requirements.
FYI I pulled most of this off other sites so I'm not claiming it as my own, but it works for me!

kadoyla
07-16-2012, 07:31 AM
Ha ha, just seen the date of your post, doh!