Offer to increment version by one

M

mr tom

Hi,

I've written some code to use form fields to create a filename, and save is
via a macro - e.g.

ActiveDocument.SaveAs FileName:="j:\CPS\ACTL\Recn requests\2005\Terms - " &
TermsSchemeName & " - " & TermsSCN & ".doc"

What I want to build is something that increments the filename by one if the
filename is already present. There is a tutorial on the Word MVP website
that does this - but what I'm looking for is a bit different - I don't want a
new version each time somebody saves their work - I'd rather check the
proposed filename against filenames in that folder, and if it's already
present, give three options:
1 - to increment filename by one
2 - to overwrite
3 - to cancel

Any thoughts?
 
H

Helmut Weber

Hi,
I'd rather check the proposed filename against filenames
in that folder, and if it's already present, give three options:
1 - to increment filename by one
2 - to overwrite
3 - to cancel

1. It is always already present.
MsgBox Dir(ActiveDocument.FullName)
2. You can't overwrite a file (fullname) by itself.
That would be just saving it.
3. What to do after cancel?

My version management looks like this:
There is an absolutely strict naming convention, like:
i:\ub3\ap\jobs\ap-001034-M00-V03.doc
Each and every macro I provide checks for the fullname.
Unless the name fits the rules for naming (grammar),
no macro will execute.
There is a button, "plus 1",
which increments the number represented after "V" in the filename.
Only drawback seems, that after version "V99", it's over.
Never happened with more than 500,000 files over ten years.


Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
M

mr tom

What I'm trying to do is run a check to see if the file already exists.

If it does, then offer the three options:
1 - Increment the version number
2 - Save over the top of the old one
3 - Cancel back to the doc.

Presumably this is a user form. I already have code for save, and can get
the increment code from the MVP website, so what I really need is to figure
out how to compare the proposed path and filename with what's already on the
disk, to see if there is a matching file already saved.

Any ideas?
 
M

mr tom

I've managed to answer my own question, so thanks to all who replied - but no
need to try again. In the msdn library, I found the floowing, which seems to
do the job very nicely:
Function DoesFileExist(strFileSpec As String) As Boolean
' Return True if file specified in the
' strFilespec argument exists.
' Return False if strFileSpec is not a valid
' file or if strFileSpec is a directory.
Const INVALID_ARGUMENT As Long = 53
On Error GoTo DoesfileExist_Err
If (GetAttr(strFileSpec) And vbDirectory) <> vbDirectory Then
DoesFileExist = CBool(Len(Dir(strFileSpec)) > 0)
Else
DoesFileExist = False
End If
DoesfileExist_End:
Exit Function
DoesfileExist_Err:
DoesFileExist = False
Resume DoesfileExist_End
End Function
 

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