Sharepoint Version number into a word document

D

David Howdon

Not sure that this is the right place for this question (I've also tried
one of the SharePoint groups). If it is not I'd be grateful if someone
could point out the right place.

What I am trying to do is to get my word
document to automatically include the current SharePoint document
version number whenever it is printed (or possibly whenever it is saved,
I've not decided which method I prefer yet).

I can do the general bit of this (setting an event handler to update the
relevant text either on saving or before printing). What I cannot find
is how to get Word to know the version number of a document.

The VB help files include the following example

---begin VBA insert---
Sub Testingversion()
Dim dlvVersions As Office.DocumentLibraryVersions
Dim dlvVersion As Office.DocumentLibraryVersion
Dim strVersionInfo As String
Set dlvVersions = ActiveDocument.DocumentLibraryVersions
If dlvVersions.IsVersioningEnabled Then
strVersionInfo = "This document has " & _
dlvVersions.Count & " versions: " & vbCrLf
For Each dlvVersion In dlvVersions
strVersionInfo = strVersionInfo & _
" - Version #: " & dlvVersion.Index & vbCrLf & _
" - Modified by: " & dlvVersion.ModifiedBy & vbCrLf & _
" - Modified on: " & dlvVersion.Modified & vbCrLf & _
" - Comments: " & dlvVersion.Comments & vbCrLf
Next
Else
strVersionInfo = "Versioning not enabled for this document."
End If
MsgBox strVersionInfo, vbInformation + vbOKOnly, "Version
Information"
Set dlvVersion = Nothing
Set dlvVersions = Nothing
End Sub
---end VBA insert---

Which does seem to return information from the SharePoint system about
each version.
However the .index property of DocumentLibraryVersion returns a version
number which is different from the version number in SharePoint in that
it starts with 1 for the latest version and higher numbers refer to
earlier versions.

Now if I was only using minor versions in Sharepoint or only using major
versions there could probably be a workaround as presumably
DocumentLibraryVersion.Count + 1 - DocumentLibraryVersion.Index would
return the correct major version number (assuming no minor versions
existed) and the string "0."&DocumentLibraryVersion.Count + 1 -
DocumentLibraryVersion.Index would return the correct minor version
number (assuming no major versions existed).

I am sure I am missing something obvious and will be deeply embarrassed
when someone points out to me what it is.
Any help greatly appreciated.

I'm using
SharePoint Server 2007 and
Word 2003 (11.8106.8107) SP2
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top