Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
previous post Increment a filename. | Excel Discussion (Misc queries) | |||
Increment a filename | Excel Discussion (Misc queries) | |||
Cell("filename") doesn't update to new filename when do save as. | Excel Worksheet Functions | |||
set filename to <filename-date on open | Excel Worksheet Functions | |||
Saving filename same as import filename | Excel Programming |