sort

R

RRodrigues

I've a code to automatically save the Fax template with a sequential number,
in a specific path:


Set fs = Application.FileSearch
With fs
.LookIn = Pathe
.FileName = "F2006*.doc"
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
Nfiles = .FoundFiles.Count
LastFile = .FoundFiles(Nfiles)
Lfile = Mid(LastFile, CharPath + 2, 20)
NChar = Len(Lfile)
Lfile = Left(Lfile, (NChar - 4))
Lfile = Mid(Lfile, 2, 7)
If Lfile <> IsNumeric(Lfile) Then GoTo Line4
FicName = Lfile + 1
MsgBox ("FicName ") & FicName
NFic = Right(FicName, 3)
FicName = "F" & FicName & ".doc"
Else
MsgBox "There were no files found."
End If
End With


On Error GoTo Line4
ChangeFileOpenDirectory Pathe
ActiveDocument.SaveAs FileName:=FicName


The files are saved in the path like F2006001.doc, F2006002.doc and so one.

However, the faxes numbers pass the 1000 and Word assumes that the last file
is F2006999 ( I know, I should start to save them as F20060001, and not as
F2006001 ).

Is there a way to sort the files in order to the last file should be the
F20061000, and not the F2006999?

Ricardo Rodrigues
 
J

Jean-Guy Marcil

RRodrigues was telling us:
RRodrigues nous racontait que :
I've a code to automatically save the Fax template with a sequential
number, in a specific path:


Set fs = Application.FileSearch
With fs
.LookIn = Pathe
.FileName = "F2006*.doc"
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
Nfiles = .FoundFiles.Count
LastFile = .FoundFiles(Nfiles)
Lfile = Mid(LastFile, CharPath + 2, 20)
NChar = Len(Lfile)
Lfile = Left(Lfile, (NChar - 4))
Lfile = Mid(Lfile, 2, 7)
If Lfile <> IsNumeric(Lfile) Then GoTo Line4
FicName = Lfile + 1
MsgBox ("FicName ") & FicName
NFic = Right(FicName, 3)
FicName = "F" & FicName & ".doc"
Else
MsgBox "There were no files found."
End If
End With


On Error GoTo Line4
ChangeFileOpenDirectory Pathe
ActiveDocument.SaveAs FileName:=FicName


The files are saved in the path like F2006001.doc, F2006002.doc and
so one.

However, the faxes numbers pass the 1000 and Word assumes that the
last file is F2006999 ( I know, I should start to save them as
F20060001, and not as F2006001 ).

Is there a way to sort the files in order to the last file should be
the F20061000, and not the F2006999?

To make things clearer, put a dash or underscore and always use zeroes to
cover for missing digits for smaller numbers. For this you have to figure
out the highest possible number.

For a maximum of 9999:

F2006_0998
F2006_0999
F2006_1000
F2006_1001
etc.

or, if you need up to 99999:

F2006_00998
F2006_00999
F2006_01000
F2006_01001

If you already have a bunch of file, you could write a quick batch file (you
could even do it fromo VBA) to rename them appropriately.

e.g.:

Dim myPath As String
Dim myName As String
Dim ShortName As String

Const NewPrefix As String = "F2006_00"

myPath = "C:\Temp\" ' Set the path.

myName = Dir(myPath) ' Retrieve the first entry.

Do While myName <> "" ' Start the loop.
'Assuming you want to preserve the 3 digits before
'the ".doc" for a total of 7 characters
ShortName = Right(myName, 7)
Name myPath & myName As myPath & NewPrefix & ShortName
myName = Dir ' Get next entry.
Loop

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
R

RRodrigues

Thanks Jean-Guy

Yes, I guess that is the best solution.

I've already thought in change all the files, but by adding a "0" instead of
a dash.

Now, what I’ve really appreciated was your attention in make the code to
change all the files.

That was really nice of you! Sincerely!

Obrigado ( Thanks )
Ricardo Rodrigues
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top