Select a few files in a folder
Dear All,
I wanted to select a few excel workbooks e.g. 3 out of 10 in a folder. How do i write the macro to do it?
example;
i have 20 workbooks in the same folder with same template. But, i wanted to select only 15 by highlighting the files that i need while the other 5 i do not want.
Thanks
NoobAvenger :)
Re: Select a few files in a folder
What do you mean? Where are you selecting the 15 files? Are you wanting a file dialog box, or are you going to have a list within a workbook/other program where you select which ones you want?
Re: Select a few files in a folder
Quote:
But, i wanted to select only 15 by highlighting the files that i need
where, how?
Re: Select a few files in a folder
Sorry for not explain it clearly. :)
This is my code for grabbing all files in one folder.
Code:
mypath = InputBox("Please enter path of the file location!", "Path")
fname = Dir(mypath & "\" & "*.xls")
Do While Len(fname) > 0
Set wb = Workbooks.Open(mypath & "\" & fname)
' i do all my stuff here....
wb.Activate
wb.Close
fname = Dir
Loop
This code does not allow me to select a few specific files.
What I wanted to do now is that I want to get prompted by the Directory Box and then I can choose a few files manually from there.
Thanks for replying. :)
Re: Select a few files in a folder
i think application.filesearch is what you want, displays a dialog and returns a list of files to loop through
Re: Select a few files in a folder
Hi westconn,
I'm not sure how to use application.filesearch
Would appreciate if you can explain it to me. Thanks a lot. sorry for trouble :)
Re: Select a few files in a folder
my error, filesearch does not display a dialog, there is an application object that does, but it is not available in excel 2000, you will have to checkout in version 2003
Re: Select a few files in a folder
vb Code:
Dim FileLocationArray As Variant
FileLocationArray = Application.GetOpenFilename("Excel Files,*.xls", 1, "Select Multiple Files", , True)
For i = LBound(FileLocationArray) To UBound(FileLocationArray)
Application.Workbooks.Open FileLocationArray(i)
Next i
Re: Select a few files in a folder
doh!! you think i could remember getopenfilename?
Re: Select a few files in a folder
i've tried it and it is really what i wanted but how do i open one workbook at a time and do all the stuff that i want and then close it then open then next workbook?
sorry for trouble..
Re: Select a few files in a folder
modify you code in post #4 to work with vanquishes code in post #7, use his for loop rather than your do loop