Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
rd rd is offline
external usenet poster
 
Posts: 6
Default saving an excel file with a serially increnmenting number

Hi,

Can you please direct me to code that allows me to save my excel files in a
serially incrementing default name, such as book201, book203, book204, etc.
as you are aware, excel always go back to book1 whenever you start a new
cession, and it doesn't know that the last book was, say book204, and that
therefore, it should suggest the next higher number, namely book205.

i hope my request is clear.

Thanks in advance.

RD


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default saving an excel file with a serially increnmenting number

Hi,

Here is a macro that I have posted a couple of time here and I think that it
will do what you want. Fee free to get back to me if it need a little
tweeking.

Sub Save_As_NewName()
Dim strInitName As String
Dim strNewName As String
Dim intAppend As Integer
Dim myFile As String
Dim strPath

'Set the next line to required file path
strPath = Application.DefaultFilePath
'Note next two variables start with same value
strInitName = strPath & "\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
If intAppend 3 Then
MsgBox "Already " & intAppend & _
" saves of this file" & Chr(13) & _
"Processing terminated"
'Insert your code here to handle the
'excessive saves.
End
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
rd rd is offline
external usenet poster
 
Posts: 6
Default saving an excel file with a serially increnmenting number

Many thanks and best regards.

RD


"OssieMac" wrote in message
...
Hi,

Here is a macro that I have posted a couple of time here and I think that
it
will do what you want. Fee free to get back to me if it need a little
tweeking.

Sub Save_As_NewName()
Dim strInitName As String
Dim strNewName As String
Dim intAppend As Integer
Dim myFile As String
Dim strPath

'Set the next line to required file path
strPath = Application.DefaultFilePath
'Note next two variables start with same value
strInitName = strPath & "\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
If intAppend 3 Then
MsgBox "Already " & intAppend & _
" saves of this file" & Chr(13) & _
"Processing terminated"
'Insert your code here to handle the
'excessive saves.
End
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




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
Loosing value of large number when saving file to CSV format Kim Luu Excel Discussion (Misc queries) 2 May 1st 06 02:40 PM
Help with Mr. Peterson's Code.. Print serially from a Sheet [email protected] Excel Programming 0 January 22nd 06 01:12 PM
Help with Mr. Peterson's Code.. Print serially from a Sheet prkhan56 Excel Programming 50 July 31st 05 01:18 PM
how to use Excel to generate alphabet serially Maxwell Excel Worksheet Functions 10 May 7th 05 03:37 PM
Saving a File Generates a Sequential Number Name Shauna Koppang Excel Programming 1 August 23rd 03 12:08 AM


All times are GMT +1. The time now is 02:58 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"