#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving Excel 2007 file in 2003 creates very large file Jon Pearce Excel Discussion (Misc queries) 2 July 16th 09 07:20 PM
Confused here Prevent Saving File - but allow ONLY File SAVEAS Met JMay Excel Discussion (Misc queries) 2 June 17th 07 04:37 PM
Excel should let me sort the file directory when saving a file Beanee70 Excel Discussion (Misc queries) 0 March 14th 06 07:03 AM
How do I stop Excel 2000 from saving file history from file that . Cathy Excel Discussion (Misc queries) 0 March 29th 05 03:27 PM
saving an excel file as an ASCII text file without delimiters Sewellst Excel Programming 4 January 7th 05 01:41 PM


All times are GMT +1. The time now is 11:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"