Public Dossier As String
Sub liste_fichiers()
Dossier = InputBox("Quel répertoire ?" & Chr(13) & "Taper le répertoire voulu sous la forme C:\NomRépertoire")
Dim lstfile As Long
Dim i As Integer, p As Picture, r As Range, c As Range, ii As Integer, f As Integer
With Application.FileSearch
.Filename = "*.jpg"
'adapter selon l'extension désirée gif, bmp
.LookIn = Dossier
.SearchSubFolders = False
For lstfile = 1 To .Execute(msoSortByFileName)
ActiveSheet.Cells(lstfile, 1).Value = Left(Mid(.FoundFiles(lstfile), Len(Dossier) + 2), Len(Mid(.FoundFiles(lstfile), Len(Dossier) + 2)) - 4)
Next lstfile
End With
Call import_images
End Sub
Sub import_images()
'auteur: richard
Application.ScreenUpdating = False
Dim i As Integer, p As Picture, r As Range, c As Range, ii As Integer, f As Integer
ii = 0
f = ActiveSheet.Range("A6556").End(xlUp).Row
Set r = ActiveSheet.Range("A1:A" & f)
ActiveSheet.DrawingObjects.Delete
For Each c In r
ii = ii + 1
If c <> "" Then
With Application.FileSearch
.NewSearch
.LookIn = Dossier
.SearchSubFolders = False
.Filename = "*" & c & ".jpg"
'adapter selon l'extension désirée gif, bmp
.Execute
For i = 1 To .FoundFiles.Count
With ActiveSheet
Set p = .Pictures.Insert(Application.FileSearch.FoundFiles(i))
.DrawingObjects(p.Name).Left = .Columns("B").Left
.DrawingObjects(p.Name).Top = .Rows(ii).Top
.DrawingObjects(p.Name).Width = .Columns("C").Left - .Columns("B").Left
.DrawingObjects(p.Name).Height = .Rows(ii + 1).Top - .Rows(ii).Top
.DrawingObjects(p.Name).Placement = xlMoveAndSize
.DrawingObjects(p.Name).PrintObject = True
End With
Exit For
Next i
End With
End If
Next c
Application.ScreenUpdating = True
End Sub