Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Need help - Filesaving - need to increment filename


Greetings, i need to modify this code to be able to increment the file
name each time i save the file.

for example when i save it to silo001.txt
i want the next one to be silo002.txt , etc..

Here is the code right now ;
----
Sub SaveCmde()

ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\guicha\bureau\cano\silo001.txt",
FileFormat:=xlTextMSDOS, CreateBackup:=False
Range("A21").Select

End Sub
----
I know you guys rock and you will help me out,
im more into hardware so thanks for your help !

Guillaume.




*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Need help - Filesaving - need to increment filename

One way

Sub SaveCmde()
Const sFilebase = "C:\Documents and Settings\guicha\bureau\cano\silo"
Dim sFile As String
Dim iNum As Long
Dim fExists As Boolean

Do
sFile = sFilebase & Format(iNum, "000") & ".txt"
fExists = Len(Dir(sFile))
If Not fExists Then
ActiveWorkbook.SaveAs Filename:=sFile, _
FileFormat:=xlTextMSDOS, _
CreateBackup:=False
Range("A21").Select
End If
Loop Until Not fExists

End Sub



--

HTH

RP
(remove nothere from the email address if mailing direct)


"Guillaume" wrote in message
...

Greetings, i need to modify this code to be able to increment the file
name each time i save the file.

for example when i save it to silo001.txt
i want the next one to be silo002.txt , etc..

Here is the code right now ;
----
Sub SaveCmde()

ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\guicha\bureau\cano\silo001.txt",
FileFormat:=xlTextMSDOS, CreateBackup:=False
Range("A21").Select

End Sub
----
I know you guys rock and you will help me out,
im more into hardware so thanks for your help !

Guillaume.




*** Sent via Developersdex http://www.developersdex.com ***



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Need help - Filesaving - need to increment filename

Sub SaveCmde()
Dim sFN As String
Static i As Integer
i = i + 1
sFN = "C:\Documents and Settings\guicha\bureau\cano\silo" & _
Format(i, "000.txt")
ActiveWorkbook.SaveAs sFN, xlTextMSDOS
Range("A21").Select
End Sub

NOTE: this will reset to 001 when you close & re-open the book.

If this is a problem, you could use a registry entry instead...

Sub SaveCmde()
Dim sFN As String
Dim i As Integer
i = GetSetting("SiloExport", "Settings", "LastSave", 0)
i = i + 1
sFN = "C:\Documents and Settings\guicha\bureau\cano\silo" & _
Format(i, "000.txt")
ActiveWorkbook.SaveAs sFN, xlTextMSDOS
SaveSetting "SiloExport", "Settings", "LastSave", i
Range("A21").Select
End Sub

Finally, neither of these will check the directory exists - or check to see if the file exists - or indeed, wether
silo002.txt is the next on in the sequence. To do that will take a bit more time & effort.

Regards - Steve.

"Guillaume" wrote in message ...

Greetings, i need to modify this code to be able to increment the file
name each time i save the file.

for example when i save it to silo001.txt
i want the next one to be silo002.txt , etc..

Here is the code right now ;
----
Sub SaveCmde()

ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\guicha\bureau\cano\silo001.txt",
FileFormat:=xlTextMSDOS, CreateBackup:=False
Range("A21").Select

End Sub
----
I know you guys rock and you will help me out,
im more into hardware so thanks for your help !

Guillaume.




*** Sent via Developersdex http://www.developersdex.com ***



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Need help - Filesaving - need to increment filename

You guys Rock !!

Works like a charm, i used the registry option, fits what i needed to
do.

i had to modify this line also for your info ;

sFN = "C:\Documents and Settings\guicha\bureau\cano\silo" & _
Format(i, "000.txt")


need to remove the .txt otherwise the file says silo001,txt.txt

Thanks again.

Guillaume.



*** Sent via Developersdex http://www.developersdex.com ***
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
previous post Increment a filename. katagrga Excel Discussion (Misc queries) 0 July 23rd 09 03:46 PM
Increment a filename alistew Excel Discussion (Misc queries) 4 July 10th 09 08:38 PM
Cell("filename") doesn't update to new filename when do save as. Louis Excel Worksheet Functions 2 March 22nd 07 07:27 PM
set filename to <filename-date on open bob engler Excel Worksheet Functions 2 July 13th 06 05:11 AM
Saving filename same as import filename Matt Excel Programming 4 February 24th 04 03:01 PM


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