Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch versioning word documents 1

Status
Not open for further replies.

scousethemoose

Programmer
Jul 14, 2002
69
AU
Hi does anyone know of a way to version multiple word documents at the same time. I have over 500 documents which all need to be versioned. If someone could point me in the right direction that world be great.
 
Hi scousethemoose,

If you're referring to documents saved with Word's 'version' feature, the document versions will already have their version numbers assigned internally. In that case, you could use a cutom DOCPROPERTY field for each version to track the version numbering, in conjunction with some vba - check out the vba Version Object for more information - supplemented with a corresponding DOCPROPERTY field in each version (which could also be added via vba).

If you're referring to documents not saved with Word's 'version' feature, but with a file-naming convention that includes the version number in the filename, then you can have each document show its 'version number' via a FILENAME field (which again could be added via vba).

Cheers
 
Hi Macropod,

I am in the process of writing a word addin which will allow me to save mulitple documents with the same version comment.
 
Hi scousethemoose,

Word's version 'feature' is generally regarded as unreliable and likely to lead to document corruption. So you might be better off not using it. For more information, see:
where you can also get some info on setting the document up to display the version numbers.

If you want to go ahead despite this, setting up versioning is quite simple - all it takes is the use of the File|Versions|Save Now process from the menus, which can also be automated through vba.

For more tips on the use of versions, see:

Another issue you need to think about if you're trying to consolidate multiple document versions into one using Word's versioning, is that you need to start with the oldest, as Version 1, then add/delete only the changes that represent each successive version. You probably don't want a situation where each 'version' amounts to a complete re-write of the previous one if only one word changed!

Cheers
 
Hi macropod,

Thanks again for your input.

I am well aware of the pit falls of versioning with word but I only intended to use the addin when I wish to give for example 10 word documents the same version comment. I thought writing an addin would save me time since I have about 500 documents which need to have a version comment set. This way I dont have to open each document individually and save the version.

 
Hi scousethemoose,

I don't believe setting the version parameter is possible without opening the document (but I may be wrong).

Assuming I'm correct, you could use code to loop through all the documents in a folder, open and save each in turn with:
ActiveDocument.Versions.Save
then close them. You might also want to add some code to check whether the document already has versioning, so that you don't needlessly update it.

Cheers
 
macropod is correct...you have to open the file.

Gerry
 
Hi

I have taken the suggestions on board. I have almost completed the addin. I think macropods idea of checking whether the document aready has versioning is a good idea. I could then give the user to continue regardless or skip the file completlely.

I'm working on an undo feature also but activedocument.versions(1).delete does not seem to work.
 
Hi scousethemoose,

Try:

With ActiveDocument.Versions
If .Count = 0 Then .Save
End With

This way, no undo is required.

Cheers
 
Hi

Although your previous suggestion negates the need to have an undo function I wanted to include one incase the user accidentally versions the wrong set of ducuments or wishes to change the comment.

I have been playing with

activedocument.versions(1).delete

This does work but it does not seem to update the document despite the fact that I save it once I perform the delete. It seems as though word does not recognise the fact that the state of the document has changed.
 
Hi scousethemoose,

For a last-version delete process, you need to use something like:
Code:
Sub VersionTest()
With ActiveDocument
     If .Versions.Count > 0 Then
        .Versions(.Versions.Count).Delete
        .Save
     End If
End With
End Sub

Cheers
 
Hi macropod, thanks again

I was using something similar to your example

Code:
With ActiveDocument
   If .Versions.Count >= 1 Then
      Debug.Print "before delete: " & .Versions.Count
      .Versions(.Versions.Count).Delete
      Debug.Print "afer delete: " & .Versions.Count
      .Save
      .Close
   End If
End With

This code does delete the recent version but whenever I reopen the document the version details reappear.
 
Hi scousethemoose,

It seems as though, in addition to deleting the version, you've also got to make some other change - any change - to the document before it will save the change to the versioning.

Cheers
 
Hi scousethemoose,

Following on from my last post, you don't actually need to insert a dummy edit into the document - all you need to do is to tell Word the document hasn't been saved. For some reason, deleting a Version doesn't do this, so the .Save never gets executed. The way to overcome that is to do something along the lines of:
Code:
Sub DeleteLastVersion()
With ActiveDocument
     If .Versions.Count > 0 Then
        .Versions(.Versions.Count).Delete
        .Saved = False
        .Save
     End If
End With
End Sub

Cheers
 
Hi Macropod

Your solution worked perfectly. Thank-you for all your help. I finished my addin today.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top