1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Function GetFolderName(Msg As String) As String
Dim bInfo As BROWSEINFO, path As String, r As Long, x As Long, pos As Integer
bInfo.pidlRoot = 0&
If IsMissing(Msg) Then
bInfo.lpszTitle = "Selectionner un répertoire de travail"
Else
bInfo.lpszTitle = Msg
End If
bInfo.ulFlags = &H1
x = SHBrowseForFolder(bInfo)
path = Space$(512)
r = SHGetPathFromIDList(ByVal x, ByVal path)
If r Then
pos = InStr(path, Chr$(0))
GetFolderName = Left(path, pos - 1)
Else
GetFolderName = ""
End If
End Function
Sub ListeFic()
Debug.Print
Dim ScanFic As Office.FileSearch
Dim NomFic As Variant
Dim NomFic1 As String
Dim Diag As String
Dim Nbr As Long
Dim I As Long
Dim chemin As Long
Dim Filename_pos As Long
Dim Dot_pos As Long
Dim revision_pos As Long
Dim folio_pos As Long
Dim liasse_pos As Long
Dim fichier As String
Set ScanFic = Application.FileSearch
Dim Rep0 As String
Rep0 = GetFolderName("Choisissez un répertoire de travail")
If Rep0 = "" Then Exit Sub
With ScanFic
.NewSearch
.LookIn = Rep0
.SearchSubFolders = False
.Filename = "*.dwg"
Nbr = .Execute(msoSortByFileName)
Diag = Format(Nbr, "0 ""fichiers trouvés""")
I = 0
For Each NomFic In .FoundFiles
I = I + 1
fichier = NomFic
'Debut Filename = Pos qui suit le dernier \
Filename_pos = InStrRev(fichier, "\", -1, 1) + 1
'Séparateur pos
Dot_pos = InStrRev(fichier, ".", -1, 1)
'Revision pos
revision_pos = InStrRev(fichier, "-", Dot_pos - 1, 1) + 1
'Folio_pos
folio_pos = InStrRev(fichier, "-", revision_pos - 2, 1) + 1
'Liasse_pos
liasse_pos = InStrRev(fichier, "-", folio_pos - 2, 1) + 1
Sheets("Feuil1").Cells(I, 1).Value = Mid(fichier, Filename_pos, revision_pos - Filename_pos - 1)
Sheets("Feuil1").Cells(I, 2).Value = Mid(fichier, folio_pos, revision_pos - folio_pos - 1)
Sheets("Feuil1").Cells(I, 3).Value = Mid(fichier, revision_pos, Dot_pos - revision_pos)
Next
End With
End Sub |
Partager