Extraction de fichiers d'images et taille des commentaires
2 réponses
garnote
Bonsoir, Bonsoir,
Voici trois macros.
Dans la macro Liste, j'utilise l'instruction
.Filename = "*.jpg;*.gif;*.bmp;*.jpeg"
Questions:
Comment faire pour récupérer TOUS les fichiers image ?
Dois-je écrire toutes les extensions possibles ?
Dans la macro ImageCommentaire, j'utilise les contorsions
suivantes pour ajuster la taille du commentaire à la taille
de l'image :
.Comment.Shape.Select
Set ici = ActiveSheet.Pictures.Insert(nom)
.Comment.Shape.Width = ici.Width
.Comment.Shape.Height = ici.Height
ici.Delete
Selection.ShapeRange.Fill.UserPicture nom
Question:
N'y aurait-il pas une instruction du genre
.Comment.Shape.TextFrame.AutoSize = True
(Ajuste la taille du commentaire au texte)
pour ajuster la taille du commentaire à celle de l'image ?
Sub Liste()
'Liste de certains fichiers images
'd'un répertoire.
'Touche de raccourci: Ctrl+l
On Error Resume Next
Application.ScreenUpdating = False
'Nom d'un répertoire
ici = "D:\Mes documents\"
r = 1
Cells(r, 2) = "Nom"
Range("B1").Font.Bold = True
r = r + 1
With Application.FileSearch
.NewSearch
.LookIn = ici
.Filename = "*.jpg;*.gif;*.bmp;*.jpeg"
.SearchSubFolders = True
.Execute
For i = 2 To .FoundFiles.Count
Cells(r, 1) = i - 1
Cells(r, 2) = .FoundFiles(i)
r = r + 1
Next i
End With
Range("A:B").EntireColumn.AutoFit
ActiveWindow.ScrollRow = 1
ActiveWindow.ScrollColumn = 1
End Sub
Sub ImageCommentaire()
'Sélectionnez une cellule contenant
'le chemin complet d'une image
'et lancez cette macro.
'Touche de raccourci: Ctrl+c
On Error GoTo FIN
Application.ScreenUpdating = False
With ActiveCell
nom = .Value
.ClearComments
.AddComment
.Comment.Visible = True
.Comment.Text Text:=""
.Comment.Shape.Select
Set ici = ActiveSheet.Pictures.Insert(nom)
.Comment.Shape.Width = ici.Width
.Comment.Shape.Height = ici.Height
ici.Delete
Selection.ShapeRange.Fill.UserPicture nom
.Comment.Visible = False
End With
End
FIN:
ActiveCell.ClearComments
End Sub
Sub InsèreImage()
'Sélectionnez une cellule contenant
'le chemin complet d'une image
'et lancez cette macro.
'Touche de raccourci: Ctrl+i
On Error Resume Next
Set ici = ActiveCell
nom = ici.Value
Set im = ActiveSheet.Pictures.Insert(nom)
im.Top = ici.Top + ici.Height
End Sub
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
Alain CROS
Bonjour,
J'ai ça si tu peux t'en inspirer.
Sub AjoutImageEnCommentaire() Dim Plg As Range, Fich$ On Error Resume Next Set Plg = Application.InputBox("Choisir une cellule", _ "Insertion d'une image en commentaire", , , , , , 8&) On Error GoTo 0 If Plg Is Nothing Then Exit Sub Fich = Application.GetOpenFilename("Métafichier Windows,*.wmf;" & _ "*.emf,Fichiers d'échange,*.jpg;*.jpeg,Portable Network " & _ "Graphics,*.png,Bitmap Windows,*.bmp;*.dib;*.rle,PC " & _ "Paintbrush,*.pcx,PostScript encapsulé,*.eps,Macintosh " & _ "PICT,*.pct,Tag Image File Format,*.tif", 4&, "Choisir une Image") ImageEnComment Plg.Address, Fich End Sub
Function ImageEnComment&(Plg$, Fich$) Dim X&, Y&, Shp As Shape, Rg As Range If Dir$(Fich) = "" Then Exit Function On Error Resume Next Set Rg = Range(Plg).Resize(1&, 1&) On Error GoTo 0 If Rg Is Nothing Then Exit Function Application.ScreenUpdating = False Set Shp = ActiveSheet.Shapes.AddOLEObject(, Fich) With Shp X = .Width Y = .Height .Delete End With With Rg On Error Resume Next .Comment.Delete On Error GoTo 0 .AddComment.Visible = False With .Comment.Shape .Fill.UserTextured Fich .Width = X .Height = Y End With End With Application.ScreenUpdating = True ImageEnComment = True End Function
Alain CROS
"garnote" a écrit dans le message de news: | Bonsoir, Bonsoir, |
Bonjour,
J'ai ça si tu peux t'en inspirer.
Sub AjoutImageEnCommentaire()
Dim Plg As Range, Fich$
On Error Resume Next
Set Plg = Application.InputBox("Choisir une cellule", _
"Insertion d'une image en commentaire", , , , , , 8&)
On Error GoTo 0
If Plg Is Nothing Then Exit Sub
Fich = Application.GetOpenFilename("Métafichier Windows,*.wmf;" & _
"*.emf,Fichiers d'échange,*.jpg;*.jpeg,Portable Network " & _
"Graphics,*.png,Bitmap Windows,*.bmp;*.dib;*.rle,PC " & _
"Paintbrush,*.pcx,PostScript encapsulé,*.eps,Macintosh " & _
"PICT,*.pct,Tag Image File Format,*.tif", 4&, "Choisir une Image")
ImageEnComment Plg.Address, Fich
End Sub
Function ImageEnComment&(Plg$, Fich$)
Dim X&, Y&, Shp As Shape, Rg As Range
If Dir$(Fich) = "" Then Exit Function
On Error Resume Next
Set Rg = Range(Plg).Resize(1&, 1&)
On Error GoTo 0
If Rg Is Nothing Then Exit Function
Application.ScreenUpdating = False
Set Shp = ActiveSheet.Shapes.AddOLEObject(, Fich)
With Shp
X = .Width
Y = .Height
.Delete
End With
With Rg
On Error Resume Next
.Comment.Delete
On Error GoTo 0
.AddComment.Visible = False
With .Comment.Shape
.Fill.UserTextured Fich
.Width = X
.Height = Y
End With
End With
Application.ScreenUpdating = True
ImageEnComment = True
End Function
Alain CROS
"garnote" <rien@absent.com> a écrit dans le message de news: ebeYw0PKGHA.1676@TK2MSFTNGP09.phx.gbl...
| Bonsoir, Bonsoir,
|
Sub AjoutImageEnCommentaire() Dim Plg As Range, Fich$ On Error Resume Next Set Plg = Application.InputBox("Choisir une cellule", _ "Insertion d'une image en commentaire", , , , , , 8&) On Error GoTo 0 If Plg Is Nothing Then Exit Sub Fich = Application.GetOpenFilename("Métafichier Windows,*.wmf;" & _ "*.emf,Fichiers d'échange,*.jpg;*.jpeg,Portable Network " & _ "Graphics,*.png,Bitmap Windows,*.bmp;*.dib;*.rle,PC " & _ "Paintbrush,*.pcx,PostScript encapsulé,*.eps,Macintosh " & _ "PICT,*.pct,Tag Image File Format,*.tif", 4&, "Choisir une Image") ImageEnComment Plg.Address, Fich End Sub
Function ImageEnComment&(Plg$, Fich$) Dim X&, Y&, Shp As Shape, Rg As Range If Dir$(Fich) = "" Then Exit Function On Error Resume Next Set Rg = Range(Plg).Resize(1&, 1&) On Error GoTo 0 If Rg Is Nothing Then Exit Function Application.ScreenUpdating = False Set Shp = ActiveSheet.Shapes.AddOLEObject(, Fich) With Shp X = .Width Y = .Height .Delete End With With Rg On Error Resume Next .Comment.Delete On Error GoTo 0 .AddComment.Visible = False With .Comment.Shape .Fill.UserTextured Fich .Width = X .Height = Y End With End With Application.ScreenUpdating = True ImageEnComment = True End Function
Alain CROS
"garnote" a écrit dans le message de news: | Bonsoir, Bonsoir, |
garnote
Bonsoir Alain,
Ouais, il y a plus de formats que je croyais ! J'explore tout ça. Merci
Serge
"Alain CROS" a écrit dans le message de news:
Bonjour,
J'ai ça si tu peux t'en inspirer.
Sub AjoutImageEnCommentaire() Dim Plg As Range, Fich$ On Error Resume Next Set Plg = Application.InputBox("Choisir une cellule", _ "Insertion d'une image en commentaire", , , , , , 8&) On Error GoTo 0 If Plg Is Nothing Then Exit Sub Fich = Application.GetOpenFilename("Métafichier Windows,*.wmf;" & _ "*.emf,Fichiers d'échange,*.jpg;*.jpeg,Portable Network " & _ "Graphics,*.png,Bitmap Windows,*.bmp;*.dib;*.rle,PC " & _ "Paintbrush,*.pcx,PostScript encapsulé,*.eps,Macintosh " & _ "PICT,*.pct,Tag Image File Format,*.tif", 4&, "Choisir une Image") ImageEnComment Plg.Address, Fich End Sub
Function ImageEnComment&(Plg$, Fich$) Dim X&, Y&, Shp As Shape, Rg As Range If Dir$(Fich) = "" Then Exit Function On Error Resume Next Set Rg = Range(Plg).Resize(1&, 1&) On Error GoTo 0 If Rg Is Nothing Then Exit Function Application.ScreenUpdating = False Set Shp = ActiveSheet.Shapes.AddOLEObject(, Fich) With Shp X = .Width Y = .Height .Delete End With With Rg On Error Resume Next .Comment.Delete On Error GoTo 0 .AddComment.Visible = False With .Comment.Shape .Fill.UserTextured Fich .Width = X .Height = Y End With End With Application.ScreenUpdating = True ImageEnComment = True End Function
Alain CROS
"garnote" a écrit dans le message de news:
| Bonsoir, Bonsoir, |
Bonsoir Alain,
Ouais, il y a plus de formats que je croyais !
J'explore tout ça.
Merci
Serge
"Alain CROS" <Personne@ICI> a écrit dans le message de news:
eASKCGQKGHA.216@TK2MSFTNGP15.phx.gbl...
Bonjour,
J'ai ça si tu peux t'en inspirer.
Sub AjoutImageEnCommentaire()
Dim Plg As Range, Fich$
On Error Resume Next
Set Plg = Application.InputBox("Choisir une cellule", _
"Insertion d'une image en commentaire", , , , , , 8&)
On Error GoTo 0
If Plg Is Nothing Then Exit Sub
Fich = Application.GetOpenFilename("Métafichier Windows,*.wmf;" & _
"*.emf,Fichiers d'échange,*.jpg;*.jpeg,Portable Network " & _
"Graphics,*.png,Bitmap Windows,*.bmp;*.dib;*.rle,PC " & _
"Paintbrush,*.pcx,PostScript encapsulé,*.eps,Macintosh " & _
"PICT,*.pct,Tag Image File Format,*.tif", 4&, "Choisir une Image")
ImageEnComment Plg.Address, Fich
End Sub
Function ImageEnComment&(Plg$, Fich$)
Dim X&, Y&, Shp As Shape, Rg As Range
If Dir$(Fich) = "" Then Exit Function
On Error Resume Next
Set Rg = Range(Plg).Resize(1&, 1&)
On Error GoTo 0
If Rg Is Nothing Then Exit Function
Application.ScreenUpdating = False
Set Shp = ActiveSheet.Shapes.AddOLEObject(, Fich)
With Shp
X = .Width
Y = .Height
.Delete
End With
With Rg
On Error Resume Next
.Comment.Delete
On Error GoTo 0
.AddComment.Visible = False
With .Comment.Shape
.Fill.UserTextured Fich
.Width = X
.Height = Y
End With
End With
Application.ScreenUpdating = True
ImageEnComment = True
End Function
Alain CROS
"garnote" <rien@absent.com> a écrit dans le message de news:
ebeYw0PKGHA.1676@TK2MSFTNGP09.phx.gbl...
| Bonsoir, Bonsoir,
|
Ouais, il y a plus de formats que je croyais ! J'explore tout ça. Merci
Serge
"Alain CROS" a écrit dans le message de news:
Bonjour,
J'ai ça si tu peux t'en inspirer.
Sub AjoutImageEnCommentaire() Dim Plg As Range, Fich$ On Error Resume Next Set Plg = Application.InputBox("Choisir une cellule", _ "Insertion d'une image en commentaire", , , , , , 8&) On Error GoTo 0 If Plg Is Nothing Then Exit Sub Fich = Application.GetOpenFilename("Métafichier Windows,*.wmf;" & _ "*.emf,Fichiers d'échange,*.jpg;*.jpeg,Portable Network " & _ "Graphics,*.png,Bitmap Windows,*.bmp;*.dib;*.rle,PC " & _ "Paintbrush,*.pcx,PostScript encapsulé,*.eps,Macintosh " & _ "PICT,*.pct,Tag Image File Format,*.tif", 4&, "Choisir une Image") ImageEnComment Plg.Address, Fich End Sub
Function ImageEnComment&(Plg$, Fich$) Dim X&, Y&, Shp As Shape, Rg As Range If Dir$(Fich) = "" Then Exit Function On Error Resume Next Set Rg = Range(Plg).Resize(1&, 1&) On Error GoTo 0 If Rg Is Nothing Then Exit Function Application.ScreenUpdating = False Set Shp = ActiveSheet.Shapes.AddOLEObject(, Fich) With Shp X = .Width Y = .Height .Delete End With With Rg On Error Resume Next .Comment.Delete On Error GoTo 0 .AddComment.Visible = False With .Comment.Shape .Fill.UserTextured Fich .Width = X .Height = Y End With End With Application.ScreenUpdating = True ImageEnComment = True End Function