Help: Saving a file

C

Centurion

This is a two part question
Can anyone point me in the right direction.

I would like save a file to a folder where
the folder is a variable that is specified
by the contents of let's say Cell(D3)

Also when saving the file which when first
saved will be called File1, I would like the
macro to check or the existance of a previously
saved file and if exists increment the name of
the file by by one digit.

ie File1, File2, File3 etc etc.






--
Regards
Centurion

****************************
Excerise is more than just
shoving a mouse over a mat.
Get out there and do some.
****************************
 
T

Tom Ogilvy

Dim sPath as String, sFile as String
Dim i as Long
sPath = Worksheets(1).Range("D3").Value
if right(sPath,1) <> "\" then
sPath = sPath & "\"
End if
i = 0
do
i = i + 1
loop until dir(sPath & "file" & i & ".xls") = ""
sfile = file & i & ".xls"

Activeworkbook.SaveAs sPath & sfile
 
C

Centurion

Tom said:
Dim sPath as String, sFile as String
Dim i as Long
sPath = Worksheets(1).Range("D3").Value
if right(sPath,1) <> "\" then
sPath = sPath & "\"
End if
i = 0
do
i = i + 1
loop until dir(sPath & "file" & i & ".xls") = ""
sfile = file & i & ".xls"

Activeworkbook.SaveAs sPath & sfile


Thanks Tom,

Will try it tomorrow, today I've thrown a sicky
to be off with the wife on Valentines day.

--
Regards
Centurion

****************************
Excerise is more than just
shoving a mouse over a mat.
Get out there and do some.
****************************
 

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