Home |
Search |
Today's Posts |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Sep 7, 12:22 am, OssieMac
wrote: Hi again, Hope the comments in the code answers you question as to what is happening in the loop. Sub Save_As_NewName() Dim strInitName As String Dim strNewName As String Dim intAppend As Integer Dim myFile As String 'Note next two variables start with same value strInitName = "C:\Book1" strNewName = strInitName Do 'Dir function searches for the file description 'which has been concatenated from strNewName 'plus the file extension (First search is for '"C:\Book1.xls") 'if file found then myFile = filename so 'therefore it exists. If not found then myFile 'is empty or = "" myFile = Dir(strNewName & ".xls") 'If myFile is not empty then increment intAppend 'and concatenate it with strInitName and save the 'concatenated string to strNewName so on the first 'loop strNewName would become "C:\Book11". 'Note that strInitName remains unchanged. 'On the next loop if "C:\Book11" exists then 'strNewName would become "C:\Book12". If myFile < "" Then intAppend = intAppend + 1 strNewName = strInitName & intAppend End If 'Next line will cause the code to loop if myfile 'is not empty. If myFile is empty then it has not 'found the most recent strNewName therefore it does 'not exist and can be used as the new file name. Loop While myFile < "" ActiveWorkbook.SaveAs Filename:= _ strNewName, FileFormat _ :=xlNormal, Password:="", WriteResPassword:="", _ ReadOnlyRecommended:= _ False, CreateBackup:=False End Sub Regards, OssieMac Perfect reply! Thanks a lot for clarifying the code. Regards, -T |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
rename current file save and delete original | Excel Programming | |||
How to set SAVE AS file name to equal A1 contents when rename file | Excel Discussion (Misc queries) | |||
overwriting a file | Excel Programming | |||
Macros in Excel - Save as and rename file | Excel Programming | |||
Macros in Excel - Save as and rename file | Excel Programming |