DanoTheKid
New Member
- Joined
- Feb 23, 2020
- Messages
- 6
- Office Version
- 2016
- Platform
- Windows
Hello, I'm trying to do a macro that let's the user select a folder with more folders inside, this folders could have images .jpg or .png. What I want is that the macro adds only the image files in the excel, any image file. What it does right now is that adds the images but only if they have for name 1.jpg, 2.jpg, 3.jpg and so on.
Any ideas? Thank you
VBA Code:
Dim Secfolder As String
MsgBox ("Busque y seleccione la carpeta que contiene las carpetas de los sectores en el punto que realizará.")
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Buscar carpeta"
.ButtonName = "Aceptar"
.InitialFileName = "C:\"
If .Show = -1 Then
Secfolder = .SelectedItems(1)
End If
Sheets("Matriz_de_Hallazgos").Select
l = 1
For i = 1 To 200
idm = (Worksheets("Matriz_de_Hallazgos").Cells(i + 2, 1))
If idm = 1 Then
Application.SpellingOptions.IgnoreCaps = True
' Colocar la ruta de las fotos; las fotos deben llamarse como números. Ej: 1.jpg'
RutaCompleta = Secfolder & "\" & "sector " & idm & "\" & l & ".jpg"
ActiveSheet.Cells(i + 2, 3).Select
With ActiveSheet.Shapes.AddPicture(Filename:=RutaCompleta, linktofile:=msoFalse, _
SaveWithDocument:=msoCTrue, Left:=0, Top:=0, Width:=0, Height:=0)
.LockAspectRatio = 0
.Top = ActiveCell.Top
.Left = ActiveCell.Left
.Width = ActiveCell.Width
.Height = ActiveCell.Height
End With
l = l + 1
End If
Next i
Any ideas? Thank you