Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert files from folder alphabetically

Status
Not open for further replies.

lemonhalls

Technical User
Jun 11, 2004
52
CA
Hi,

I have this code that inserts all the files one after another in a folder.
I would like to first arrange the files in the folder into an alphabetical order before proceeding with the insert.

How does one check or make sure the files are alphabetically arranged?

thanks!


_________________
With Application.FileSearch
.NewSearch
.LookIn = activeDir
.SearchSubFolders = False
.FileName = "*.doc"
.MatchTextExactly = False
If .Execute() > 0 Then

For i = 1 To .FoundFiles.Count
Selection.InsertFile FileName:=.FoundFiles(i), Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False

End with

 
Not sure what you're after here - the order of the files in the folder should have no effect on your ability to add files into it. Further, Windows should automatically alphabetize the files when you view the folder from Explorer.

VBAjedi [swords]
 
Thanks Jedi!

I agree that most of the time Windows automatically alphabetize the files when you view the folder, but I wanted to add a line in my code that would check the files in the folder are placed alphabetically instead of ie. modified date, or created date.
I would like it to sort by the name (column) but not sure of the code.

I further investigated and changed the if statement to

If .Execute(SortBy:=msoSortByFileName, _
sortOrder:=msoSortOrderAscending) > 0 Then

I tested it and worked fine. Are there better approaches?

Thanks!
 
Geez!

With a SIMPLE button click, you can order a folder by Name or Size ot Type of Date Modified.

Are "WE" Swallowing a Camel, and Straining at a Gnat?

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at faq222-2244
 
thanks Skip,

I appreciate your comment, the reason I added the sorting into the code is in case the user did not click to sort by name. just to be safe.


lemonhalls
 
Do you wipe their noses, too??? ;-)

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at faq222-2244
 
Here's the point.

You go thru all this nonsense of sorting files in a folder.

Mr. A goes to the folder, see's the files nicely sorted by Name, and in the process of browsing, sorts the folder in some other order. After all, one of the GREAT features of the GUI environment is...

[red]POINT 'N' CLICK[/red]

;-)

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at faq222-2244
 
allow me to clarify..

I agree, Mr A might sort the folder in another order.
That was the intention of my including

SortBy:=msoSortByFileName, _ sortOrder:=msoSortOrderAscending

this statement, if the user does sort it in a different order, when the function is called, it will take the files in an alphabetical order, despite their current state.

correct me if this statement is not doing what I'm intending.
 
This routine is run from an application like Access when some event occurs. I don't know how often this event occurs. It could be once every 5 minutes, in which case if I were the user, I'd be ticked if it occured while I was browsing, or it could occur whenever Miss. B hits a button, which could be seldom or never at all.

:cool:

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at faq222-2244
 
from the code in the original post, it was meant to occur when the program does a file search, and right before it inserts the files. this way the files would be inserted alphabetically.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top