hi
I search for macro brings for all files based on two cells. theis directory "
" contains many folders(AL1,AL2,AL3,MAH1,MAHM2,.....) and each folder contains subfolders (JAN,FEB,MAR....) and cell value E2= dropdown contains folders((AL1,AL2,AL3,MAH1,MAHM2,.....),F2= dropdown contains(JAN,FEB,MAR....) . so what I want if I select just E1 the customer then should brings all of files for all subfolders in column A and hyperlink to open when press for any file and if I select E2,F2 together then should show specific files for specific subfolder(F2) for specific folder(E2)
case1 when select E2 then should shows all files whether folder or subfolder
CASE2
when select E2,F2 then should show the only files based on subfolder F2 which is relating the folder In E2
this is what I have by need mod this code
I search for macro brings for all files based on two cells. theis directory "
" contains many folders(AL1,AL2,AL3,MAH1,MAHM2,.....) and each folder contains subfolders (JAN,FEB,MAR....) and cell value E2= dropdown contains folders((AL1,AL2,AL3,MAH1,MAHM2,.....),F2= dropdown contains(JAN,FEB,MAR....) . so what I want if I select just E1 the customer then should brings all of files for all subfolders in column A and hyperlink to open when press for any file and if I select E2,F2 together then should show specific files for specific subfolder(F2) for specific folder(E2)
case1 when select E2 then should shows all files whether folder or subfolder
a.xlsm | ||||||||
---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | |||
1 | ITEM | FILE NAME | FOLDER | SUBFOLDER | ||||
2 | 1 | MM.AVI | ALI1 | |||||
3 | 2 | MM1.MP4 | ||||||
4 | 3 | MU1.MP3 | ||||||
5 | 4 | KK.XLS | ||||||
6 | 5 | LL.XLSM | ||||||
7 | 6 | REPORT.PDF | ||||||
8 | 7 | INV1.PDF | ||||||
9 | 8 | INV2.PDF | ||||||
10 | 9 | INV3.PDF | ||||||
11 | 10 | INV4.PDF | ||||||
12 | 11 | INV5.PDF | ||||||
13 | 12 | INV6.PDF | ||||||
14 | 13 | INV7.PDF | ||||||
15 | 14 | INV8.PDF | ||||||
List Details |
Cells with Data Validation | ||
---|---|---|
Cell | Allow | Criteria |
E2 | List | ALI1,ALI2,ALI3 |
F2 | List | JAN,FEB,MAR |
CASE2
when select E2,F2 then should show the only files based on subfolder F2 which is relating the folder In E2
a.xlsm | ||||||||
---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | |||
1 | ITEM | FILE NAME | FOLDER | SUBFOLDER | ||||
2 | 1 | MM.AVI | ALI1 | JAN | ||||
3 | 2 | MM1.MP4 | ||||||
4 | 3 | MU1.MP3 | ||||||
5 | 4 | KK.XLS | ||||||
6 | 5 | LL.XLSM | ||||||
7 | 6 | REPORT.PDF | ||||||
8 | 7 | INV1.PDF | ||||||
List Details |
Cells with Data Validation | ||
---|---|---|
Cell | Allow | Criteria |
E2 | List | ALI1,ALI2,ALI3 |
F2 | List | JAN,FEB,MAR |
this is what I have by need mod this code
VBA Code:
Sub getfiles()
Dim oFSO As Object
Dim oFolder As Object
Dim oFile As Object, sf
Dim i As Integer, colFolders As New Collection, ws As Worksheet
Set ws = ActiveSheet
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder("D:\files\customers")
colFolders.Add oFolder 'start with this folder
Do While colFolders.Count > 0 'process all folders
Set oFolder = colFolders(1) 'get a folder to process
colFolders.Remove 1 'remove item at index 1
For Each oFile In oFolder.Files
ws.Cells(i + 1, 1) = oFile.Name
i = i + 1
' End If
Next oFile
For Each sf In oFolder.Subfolders
colFolders.Add sf 'add to collection for processing
Next sf
Loop
End Sub