|
-
Jun 14th, 2000, 07:55 PM
#1
Thread Starter
Junior Member
I have this code :
Newdoc.SaveAs TextBox1 & ".doc"
It works except when the file "TextBox1.doc" already exist.
Is there a way to say : if the file "TextBox1.doc" exist then SaveAs "TextBox12.doc". ?
-
Jun 14th, 2000, 07:57 PM
#2
_______
'does file exist using fso
Dim sFile$
sFile = "Name And Path Of Your File"
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.fileexists(sFile$) = True Then
MsgBox "File Exists...Your code here!"
Else
MsgBox "Does Not Exist...Your code here!"
End If
Set fs = Nothing
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Jun 14th, 2000, 08:01 PM
#3
Thread Starter
Junior Member
Thanks HeSaidJoe.
But what if I want a code that automatically save the document with a +1 at the end.
I mean if document1.doc exist then saveas document2.doc, if document2.doc exist then saveas document3.doc, and so on.
Do you have any idea ?
-
Jun 14th, 2000, 08:40 PM
#4
Fanatic Member
Here's a function (I used code from HeSaidJoe)
Click on Project|References and add "Microsoft Scripting Runtime"
Code:
' This will return True if saved, and False if not
Public Function SaveNextInstance(ByVal f as String) as Boolean
Dim fs As Scripting.FileSystemObject
Dim docnum as Integer
Set fs = New FileSystemObject
If fs.FileExists(f) then
On Error Goto ErrorHandler
docnum = Int(Val(Mid(f, Len(f) - 7, 3)
docnum = docnum + 1
f = Mid(f, 1, Len(f) - 7) & Format(docnum, "0##") & ".doc"
Else
On Error Goto ErrorHandler
f = f & "000.doc"
End if
NewDoc.SaveAs f
SaveNextInstance = True
Exit Function
ErrorHandler:
SaveNextInstance = False
End Function
I haven't tested it, but it should work.
r0ach™
Don't forget to rate the post
-
Jun 14th, 2000, 08:49 PM
#5
Thread Starter
Junior Member
Thanks for all this code, it'll help me a lot.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|