Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
File saving
Hi All,
I would to write a macro that saves automatically an open workbook with the name that is on cell B2, but if the file already exist the macro add a "running number" to the file name (i.e. FileName1, FileName2,etc.,) Can anyOne help? Thanks' Avner Mediouni R&D Physicist |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
File saving
Sub testit()
Dim sBase As String Dim sFile As String Dim i As Long Dim rtn sBase = Range("B2").Value If Right(sBase, 4) = ".xls" Then sBase = Left(sBase, Len(sBase) - 4) End If sFile = sBase Do rtn = FileExists(sFile) If rtn Then i = i + 1 sFile = sBase & " " & i End If Loop Until Not rtn ActiveWorkbook.SaveAs sFile End Sub '----------------------------------------------------------------- Function FileExists(File) As Boolean '----------------------------------------------------------------- Dim sFile As String On Error Resume Next sFile = Dir(File & ".xls") If sFile < "" Then FileExists = True End If End Function -- HTH Bob Phillips "Avner mediouni" wrote in message ... Hi All, I would to write a macro that saves automatically an open workbook with the name that is on cell B2, but if the file already exist the macro add a "running number" to the file name (i.e. FileName1, FileName2,etc.,) Can anyOne help? Thanks' Avner Mediouni R&D Physicist |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Saving Excel 2007 file in 2003 creates very large file | Excel Discussion (Misc queries) | |||
Confused here Prevent Saving File - but allow ONLY File SAVEAS Met | Excel Discussion (Misc queries) | |||
Excel should let me sort the file directory when saving a file | Excel Discussion (Misc queries) | |||
How do I stop Excel 2000 from saving file history from file that . | Excel Discussion (Misc queries) | |||
saving an excel file as an ASCII text file without delimiters | Excel Programming |