ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Auto-increment file name (https://www.excelbanter.com/excel-programming/410505-auto-increment-file-name.html)

Matthew Pfluger

Auto-increment file name
 
I want to save several files with a naming convention as follows:
"FilePrefix_###.xls", where the ### would be a number ranging from 1 to 999.
The routine would search through a folder and determine if there were any
other files named "FilePrefix_" and choose the next number in the sequence.

What would be the best way to search through a give folder path? FileSearch
object? I would appreciate some advice.

Thanks,
Matthew Pfluger

Jacques ALARDET

Auto-increment file name
 
Hello Matthew

If I have inderstand your question : I use this procédure for stock files in
memory. Since I work in memry for find the maxumum number


Function MSOStockerFichiers(Chemin As String) As Integer
'_Stocker les fichiers d'un dossier
' Résultat = nombre de fichier trouvés dans le dossier
'-
MSOStockerFichiers = 0
Set MonFSO =
CreateObject("Scripting.FileSystemObject")
Erase TZ5_Fichier
TZ5_nb = 0
If MonFSO.FolderExists(Chemin) = False Then GoTo E1
For Each ForObject In MonFSO.GetFolder(Chemin).Files
With ForObject
TZ5_nb = TZ5_nb + 1
TZ5_Fichier(TZ5_nb) = .Name
End With
Next
MSOStockerFichiers = TZ5_nb
FP: Exit Function
'=
E1: MsgBox "Dossier non trouvé " & Chemin: GoTo FP
End Function

J a c q u e s

"Matthew Pfluger" a écrit dans le
message de ...
I want to save several files with a naming convention as follows:
"FilePrefix_###.xls", where the ### would be a number ranging from 1 to
999.
The routine would search through a folder and determine if there were any
other files named "FilePrefix_" and choose the next number in the
sequence.

What would be the best way to search through a give folder path?
FileSearch
object? I would appreciate some advice.

Thanks,
Matthew Pfluger



Matthew Pfluger

Auto-increment file name
 
Jacques,

Thank you for your help. This will be a great starting point!

Matthew Pfluger

"Jacques ALARDET" wrote:

Hello Matthew

If I have inderstand your question : I use this procédure for stock files in
memory. Since I work in memry for find the maxumum number


Function MSOStockerFichiers(Chemin As String) As Integer
'_Stocker les fichiers d'un dossier
' Résultat = nombre de fichier trouvés dans le dossier
'-
MSOStockerFichiers = 0
Set MonFSO =
CreateObject("Scripting.FileSystemObject")
Erase TZ5_Fichier
TZ5_nb = 0
If MonFSO.FolderExists(Chemin) = False Then GoTo E1
For Each ForObject In MonFSO.GetFolder(Chemin).Files
With ForObject
TZ5_nb = TZ5_nb + 1
TZ5_Fichier(TZ5_nb) = .Name
End With
Next
MSOStockerFichiers = TZ5_nb
FP: Exit Function
'=
E1: MsgBox "Dossier non trouvé " & Chemin: GoTo FP
End Function

J a c q u e s

"Matthew Pfluger" a écrit dans le
message de ...
I want to save several files with a naming convention as follows:
"FilePrefix_###.xls", where the ### would be a number ranging from 1 to
999.
The routine would search through a folder and determine if there were any
other files named "FilePrefix_" and choose the next number in the
sequence.

What would be the best way to search through a give folder path?
FileSearch
object? I would appreciate some advice.

Thanks,
Matthew Pfluger




All times are GMT +1. The time now is 07:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com