Boostez vos compétences Excel avec notre communauté !
Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !
Sub CommandButton5_Cliquer()
'place les photos dans la colonne A (le prénom est en colonne B et le nom en colonne C
‘les photos dans TROMBINOSCOPE sont nommées Prénom + espace + Nom.JPG
[A3:A161].ClearContents: [A2] = 0
'placement des formules
Application.ScreenUpdating = True
[A3].FormulaLocal = "=NBVAL(B3)+A2*NBVAL(B3)"
'en ce qui concerne mon fichier actuel :
'en [A3] prend la valeur 1,
'en [A4] prend la valeur 2, etc ...
'jusqu'à la ligne 99 où [A99] prend la valeur 99
Range("A3").Copy Range("A4:A161")
'efface les photos éventuellement en place
Dim s As Shape
'Application.ScreenUpdating = False
For Each s In ActiveSheet.Shapes
If Not Intersect(s.TopLeftCell, [A3:A161]) Is Nothing Then
s.Delete
End If
Next
'place les photos du TROMBINOSCOPE
Dim Row As Integer, col As Integer
Dim File As Variant, Fso As Object
Set Fso = CreateObject("Scripting.FileSystemObject")
Application.ScreenUpdating = False
[A1] = 0
Row = 3
col = Columns("A").Column
[A3].FormulaLocal = "=NBVAL(B3)+A2*NBVAL(B3)"
PhotoDir = [AM1] & "TROMBINOSCOPE\"
For Row = 3 To 161
For Each File In Fso.GetFolder([PhotoDir]).Files
If File.Name Like "*.jpg" Then
[A1] = [A1] + 1
If Cells(Row, col + 1) & " " & Cells(Row, col + 2) = Fso.getBasename(File) Then
'la ligne suivante bloque la macro :
PlaceThePictureInCenterRange Cells(Row, col), Shapes.AddPicture(File, False, True, 20, 20, -1, -1), 90
' la photo .JPG n'apparaît pas dns la cellule...
'Je ne trouve pas l'erreur.
End If
End If
Next
Next
Set Fso = Nothing ' Libération mémoire
Application.ScreenUpdating = True
End Sub
Ces instructions :dans la zone A1, j'ai quelques boutons d'appel de macro... qui s'effacent à l'issue du fonctionnement de ces lignes vba.
For Each s In .Shapes
If Not Intersect(s.TopLeftCell, .Columns(1)) Is Nothing Then s.Delete 'RAZ
Next s
Sub PlacerPhotos()
Dim chemin$, W#, s As Shape, lig&, fichier$
chemin = ThisWorkbook.Path & "\TROMBINOSCOPE\"
Application.ScreenUpdating = False
With ActiveSheet
.Columns(1).ColumnWidth = 16 'largeur de colonne A à adapter
W =...
Sub PlacerPhotos()
Dim chemin$, fichier$, W#, s As Shape, n%
chemin = ThisWorkbook.Path & "\TROMBINOSCOPE\"
fichier = Dir(chemin & "*.jpg") '1er fichier du dossier
Application.ScreenUpdating = False
With ActiveSheet
.Columns(1).ColumnWidth = 12 'largeur de colonne A à adapter
W = .Columns(1).Width 'largeur en points
For Each s In .Shapes
If Not Intersect(s.TopLeftCell, .Columns(1)) Is Nothing Then s.Delete 'RAZ
Next s
While fichier <> ""
n = n + 1
Set s = .Shapes.AddPicture(chemin & fichier, msoFalse, msoTrue, 0, .Rows(n + 2).Top, 0, 0)
s.LockAspectRatio = True
s.Width = W 'la photo prend la largeur de la cellule
.Rows(n + 2).RowHeight = W * s.Height / s.Width + 0.7 'la cellule prend la hauteur de la photo + marge
.Cells(n + 2, 2) = Left(fichier, Len(fichier) - 4) 'prénom et nom en colonne B
fichier = Dir 'fichier suivant
Wend
End With
End Sub
Vous voulez dire en colonnes B et C, comme déjà dit c'est laborieux ! Et il y a le risque de fautes d'orthographe !J'ai créé une feuille ESSAI en plaçant mes 97 prénoms et Noms en colonnes A et B.
Sub PlacerPhotos()
Dim chemin$, fichier$, W#, s As Shape, n%
chemin = ThisWorkbook.Path & "\TROMBINOSCOPE\"
fichier = Dir(chemin & "*.jpg") '1er fichier du dossier
Application.ScreenUpdating = False
With ActiveSheet
.Columns(1).ColumnWidth = 12 'largeur de colonne A à adapter
W = .Columns(1).Width 'largeur en points
For Each s In .Shapes
If Not Intersect(s.TopLeftCell, .Columns(1)) Is Nothing Then s.Delete 'RAZ
Next s
.Range("B3:C" & .Rows.Count).ClearContents 'RAZ
While fichier <> ""
n = n + 1
Set s = .Shapes.AddPicture(chemin & fichier, msoFalse, msoTrue, 0, .Rows(n + 2).Top, 0, 0)
s.LockAspectRatio = True
s.Width = W 'la photo prend la largeur de la cellule
.Rows(n + 2).RowHeight = W * s.Height / s.Width + 0.7 'la cellule prend la hauteur de la photo + marge
s.Name = Left(fichier, Len(fichier) - 4) 'renomme la Shape
.Cells(n + 2, 2) = Left(fichier, Len(fichier) - 4) 'prénom et nom en colonne B
fichier = Dir 'fichier suivant
Wend
With .Range("B3:B" & n + 2)
.TextToColumns .Cells(1), Space:=True 'commande Convertir
.EntireRow.Sort .Columns(2), xlAscending, Header:=xlNo 'tri sur la colonne C (noms)
End With
End With
End Sub
Sub Trombino()
Dim FSO As Object, DC As Object
' Si early binding :
' Dim FSO As Scripting.FileSystemObject
' Dim DC As Scripting.Dictionary
Dim Wsh As Worksheet, RépTrombi As String, DébNoms As Range, DébPhotos As Range, Shp As Shape, Cible As Range, W As Double, Col, LMax, Tb
RépTrombi = ThisWorkbook.Path & "\TROMBINOSCOPE"
Set Wsh = Feuil1
Set DébNoms = Wsh.[B1] 'première cellule contenant les noms
Set DébPhotos = Wsh.[A1] 'première cellule contenant les photos
W = DébPhotos.Width 'Largeur en point des cellules cible
Set FSO = CreateObject("Scripting.FileSystemObject")
Set DC = CreateObject("Scripting.Dictionary")
' Si early binding :
' Set FSO = New Scripting.FileSystemObject
' Set DC = New Scripting.Dictionary
With Wsh
Tb = .Range(DébNoms, .Cells(.Cells(.Rows.Count, DébNoms.Column).End(xlUp).Row, 2)).Resize(, 2)
End With
'Effacer les Photos précédentes si elles existent
Col = DébPhotos.Column
LMax = UBound(Tb, 1)
For Each Shp In Feuil1.Shapes
If Shp.Type = msoPicture And Shp.TopLeftCell.Column = Col And Shp.TopLeftCell.Row <= LMax Then
Shp.Delete
End If
Next
Set Photos = FSO.GetFolder(RépTrombi).Files
For Each Photo In Photos
If UCase(Photo.Name) Like "*.JPG" Then
DC(UCase(Photo.Name)) = Photo.Path
End If
Next
For i = 1 To LMax
Set Cible = DébPhotos.Offset(i - 1)
Clef = UCase(Tb(i, 1)) & " " & UCase(Tb(i, 2)) & ".JPG"
If DC.Exists(Clef) Then
Set s = Wsh.Shapes.AddPicture(DC(Clef), msoFalse, msoTrue, 0, Cible.Top, 0, 0)
s.LockAspectRatio = True
s.Width = W 'la photo prend la largeur de la cellule cible
Cible.EntireRow.RowHeight = W * s.Height / s.Width + 0.7 'la cellule prend la hauteur de la photo + marge
End If
Next
End Sub
Qu'est-ce que c'est que cette histoire, vous utilisez bien la colonne B pour le prénom et la colonne C pour le nom ???JOB75 est tout près, aussi, de La solution, mais sa macro doit me préserver les colonnes C et suivantes.
C'est simple, utilisez l'espace insécable CAR(160) entre LE et BRUN.... et non pas comme avec votre dernière macro
en colonne B : Jean-Michel·LB
en colonne C : LE
en colonne D : BRUN
We use cookies and similar technologies for the following purposes:
Est ce que vous acceptez les cookies et ces technologies?
We use cookies and similar technologies for the following purposes:
Est ce que vous acceptez les cookies et ces technologies?