Andyatwork
Board Regular
- Joined
- Mar 29, 2010
- Messages
- 94
Hello Hivemind,
I’m coding a workbook that allows a user to select 3 files from an open file dialog box and have them automatically pasted and formatted to a prescribed reporting requirement.
It works provided the files are sorted A to Z in the folder before the user selects them, but it falls over if the folder is sorted Z to A. I don’t want to rely on the user sorting by filename before selecting the files.
The pasting and formatting performed is dependent on letter flags in the filenames. e.g.,
Specifically, data in one file must be pasted after data in another file. B must follow A, not the other way round.
Reading around leads me to believe that sorting
from a filedialog isn’t possible.
While I can probably bodge something clunky I am going to assume that there is a more elegant solution I don’t know about and was hoping someone could point me in the right direction?
Something to do with arrays maybe? I'm thinking I could write the filepaths from SelectedItems to an array, sort the array alphabetically and squirt the array back into Selecteditems, or just run the rest of my code on the array filepaths in turn. My Array-Fu is weak though.
Hope you can help, many thanks.
Andy
I’m coding a workbook that allows a user to select 3 files from an open file dialog box and have them automatically pasted and formatted to a prescribed reporting requirement.
It works provided the files are sorted A to Z in the folder before the user selects them, but it falls over if the folder is sorted Z to A. I don’t want to rely on the user sorting by filename before selecting the files.
The pasting and formatting performed is dependent on letter flags in the filenames. e.g.,
Code:
filepath = vrtSelectedItem
filetype = Left(Right(filepath, 8), 1)
fileflag = Left(Right(filepath, 17), 1)
Specifically, data in one file must be pasted after data in another file. B must follow A, not the other way round.
Reading around leads me to believe that sorting
Code:
Each vrtSelectedItem In .SelectedItems
While I can probably bodge something clunky I am going to assume that there is a more elegant solution I don’t know about and was hoping someone could point me in the right direction?
Something to do with arrays maybe? I'm thinking I could write the filepaths from SelectedItems to an array, sort the array alphabetically and squirt the array back into Selecteditems, or just run the rest of my code on the array filepaths in turn. My Array-Fu is weak though.
Hope you can help, many thanks.
Andy