hi
I have this code it brings all information from the subfolders & files , then create hyperlink and open it in two columns A,B , but what I look for it . it should split each 10 file in specific column individually . so when bring the subfolders under each of them should split each 10 files in separately column with the same borders and formatting as in my picture .
I hope my idea is clear
I have this code it brings all information from the subfolders & files , then create hyperlink and open it in two columns A,B , but what I look for it . it should split each 10 file in specific column individually . so when bring the subfolders under each of them should split each 10 files in separately column with the same borders and formatting as in my picture .
I hope my idea is clear
VBA Code:
Public oldNR As Long
Sub HyperlinkDirectory()
Dim fPath As String
Dim fType As String
Dim fname As String
Dim NR As Long
Dim AddLinks As Boolean
'Select folder
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.InitialFileName = "C:\Users\OSE\Desktop\11\"
.Show
If .SelectedItems.Count > 0 Then
fPath = .SelectedItems(1) & "\"
Else
Exit Sub
End If
End With
'Types of files
fType = Application.InputBox("What kind of files? Type the file extension to collect" _
& vbLf & vbLf & "(Example: xls, doc, txt, pdf, *)", "File Type", "PDF", Type:=2)
If fType = "False" Then Exit Sub
'Option to create hyperlinks
AddLinks = MsgBox("Add hyperlinks to the file listing?", vbYesNo) = vbYes
'Create report
Application.ScreenUpdating = False
NR = 4
With ActiveSheet
.Range("A:C").Clear
.[A2] = "LIST OF FILES"
.[B2] = "Modified Date"
Call FindFilesAndAddLinks(fPath, fType, NR, AddLinks)
End With
With ActiveSheet
.Range("A:B").Columns.AutoFit
.Range("B:B").HorizontalAlignment = xlCenter
Range("B:B").Select
Selection.NumberFormat = "d-mmm-yy h:mm AM/pm"
End With
With ActiveSheet
Range("A2").Select
Selection.Font.Bold = True
Range("B2").Select
Selection.Font.Bold = True
Columns("A:A").Select
Selection.Font.Underline = xlUnderlineStyleNone
End With
Application.ScreenUpdating = True
End Sub
Private Sub FindFilesAndAddLinks(fPath As String, fType As String, ByRef NR As Long, AddLinks As Boolean)
Dim fname As String
Dim oFS As New FileSystemObject
Dim oDir
'Files under current dir
fname = Dir(fPath & "*." & fType)
With ActiveSheet
'Write folder name
.Range("A" & NR) = fPath
.Range("A" & NR).Select
If AddLinks Then .Hyperlinks.Add Anchor:=Selection, _
Address:=fPath, _
TextToDisplay:="FOLDER NAME: " & " " & UCase(Split(fPath, "\")(UBound(Split(fPath, "\")) - 1))
Selection.Font.Bold = True
Selection.Font.Size = 10
Selection.Font.Name = "Arial"
Selection.Font.Underline = xlUnderlineStyleNone
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent3
.TintAndShade = 0.399975585192419
.PatternTintAndShade = 0
End With
With Selection.Font
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
End With
NR = NR + 2
Do While Len(fname) > 0
'filename
If .Range("A" & NR) <> "" Then Debug.Print "Overwriting " & NR
.Range("A" & NR) = fname
'modified
.Range("B" & NR) = FileDateTime(fPath & fname)
'hyperlink
.Range("A" & NR).Select
If AddLinks Then .Hyperlinks.Add Anchor:=Selection, _
Address:=fPath & fname, _
TextToDisplay:=fname
'set for next entry
NR = NR + 1
fname = Dir
Loop
'Files under sub dir
Set oDir = oFS.GetFolder(fPath)
For Each oSub In oDir.SubFolders
NR = NR + 1
Call FindFilesAndAddLinks(oSub.Path & "\", fType, NR, AddLinks)
Next oSub
End With
ActiveWindow.DisplayGridlines = False
End Sub
ff.xlsm | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
E | F | G | H | I | J | K | L | M | N | O | P | |||
1 | ||||||||||||||
2 | LIST OF FILES | Modified Date | LIST OF FILES | Modified Date | LIST OF FILES | Modified Date | ||||||||
3 | ||||||||||||||
4 | ITEM | FOLDER NAME: 11 | ITEM | FOLDER NAME: 11 | ITEM | FOLDER NAME: 11 | ||||||||
5 | 1 | 11.pdf | 3-Feb-21 9:42 AM | 1 | 21.pdf | 3-Feb-21 9:42 AM | 1 | 31.pdf | 3-Feb-21 9:42 AM | |||||
6 | 2 | 12.pdf | 3-Feb-21 9:45 AM | 2 | 22.pdf | 3-Feb-21 9:45 AM | 2 | 22.pdf | 3-Feb-21 9:45 AM | |||||
7 | 3 | 13.pdf | 3-Feb-21 9:47 AM | 3 | 23.pdf | 3-Feb-21 9:47 AM | ||||||||
8 | 4 | 14.pdf | 3-Feb-21 9:42 AM | 4 | 24.pdf | 3-Feb-21 9:42 AM | ||||||||
9 | 5 | 15.pdf | 3-Feb-21 9:42 AM | 5 | 25.pdf | 3-Feb-21 9:42 AM | ||||||||
10 | 6 | 16.pdf | 3-Feb-21 9:42 AM | 6 | 26.pdf | 3-Feb-21 9:42 AM | ||||||||
11 | 7 | 17.pdf | 3-Feb-21 9:42 AM | 7 | 27.pdf | 3-Feb-21 9:42 AM | ||||||||
12 | 8 | 18.pdf | 3-Feb-21 9:42 AM | 8 | 28.pdf | 3-Feb-21 9:42 AM | ||||||||
13 | 9 | 19.pdf | 4-Feb-21 9:42 AM | 9 | 29.pdf | 4-Feb-21 9:42 AM | ||||||||
14 | 10 | 20.pdf | 5-Feb-21 9:42 AM | 10 | 30.pdf | 5-Feb-21 9:42 AM | ||||||||
15 | ||||||||||||||
16 | ITEM | FOLDER NAME: AA | ITEM | FOLDER NAME: AA | ITEM | FOLDER NAME: AA | ||||||||
17 | 1 | A11.pdf | 3-Feb-21 9:42 AM | 1 | A21.pdf | 3-Feb-21 9:42 AM | 1 | A31.pdf | 3-Feb-21 9:42 AM | |||||
18 | 2 | A12.pdf | 3-Feb-21 9:45 AM | 2 | A22.pdf | 3-Feb-21 9:45 AM | ||||||||
19 | 3 | A13.pdf | 3-Feb-21 9:48 AM | 3 | A23.pdf | 3-Feb-21 9:48 AM | ||||||||
20 | 4 | A14.pdf | 3-Feb-21 9:50 AM | 4 | A24.pdf | 3-Feb-21 9:50 AM | ||||||||
21 | 5 | A15.pdf | 3-Feb-21 9:53 AM | 5 | A25.pdf | 3-Feb-21 9:53 AM | ||||||||
22 | 6 | A16.pdf | 3-Feb-21 9:56 AM | 6 | A26.pdf | 3-Feb-21 9:56 AM | ||||||||
23 | 7 | A17.pdf | 3-Feb-21 9:58 AM | 7 | A27.pdf | 3-Feb-21 9:58 AM | ||||||||
24 | 8 | A18.pdf | 3-Feb-21 10:01 AM | 8 | A28.pdf | 3-Feb-21 10:01 AM | ||||||||
25 | 9 | A19.pdf | 3-Feb-21 10:04 AM | 9 | A29.pdf | 3-Feb-21 10:04 AM | ||||||||
26 | 10 | A20.pdf | 3-Feb-21 10:06 AM | 10 | A30.pdf | 3-Feb-21 10:06 AM | ||||||||
27 | ||||||||||||||
SHEET |