Sub InsertPictures()
Dim SFolder As Object, FSO As Object, Opic As Object
Dim sFile As Object, RngCnt As Integer
Dim ws As Worksheet
Set ws = ActiveSheet ' or a specific sheet
Set FSO = CreateObject("Scripting.FileSystemObject")
'Where the pictures are. Change to suit
Set SFolder = FSO.GetFolder("C:\Users\User\Pictures\")
For Each sFile In SFolder.Files
RngCnt = RngCnt + 1
Set Opic = Application.ActiveSheet.Shapes.AddPicture(SFolder.Path & "\" & sFile.Name, False, True, 1, 1, 1, 1)
Opic.Left = ws.Range("A" & RngCnt).Left
Opic.Top = ws.Range("A" & RngCnt).Top
Opic.Width = ws.Range("A" & RngCnt).Width
Opic.Height = ws.Range("A" & RngCnt).Height
ws.Range("B" & RngCnt).Value = sFile.Name
Next sFile
Set Opic = Nothing
Set SFolder = Nothing
Set FSO = Nothing
End Sub
Thanks for looking at this for meSub InsertPictures() Dim SFolder As Object, FSO As Object, Opic As Object Dim sFile As Object, RngCnt As Integer Dim ws As Worksheet Set ws = ActiveSheet ' or a specific sheet Set FSO = CreateObject("Scripting.FileSystemObject") 'Where the pictures are. Change to suit Set SFolder = FSO.GetFolder("C:\Users\User\Pictures\") For Each sFile In SFolder.Files RngCnt = RngCnt + 1 Set Opic = Application.ActiveSheet.Shapes.AddPicture(SFolder.Path & "\" & sFile.Name, False, True, 1, 1, 1, 1) Opic.Left = ws.Range("A" & RngCnt).Left Opic.Top = ws.Range("A" & RngCnt).Top Opic.Width = ws.Range("A" & RngCnt).Width Opic.Height = ws.Range("A" & RngCnt).Height ws.Range("B" & RngCnt).Value = sFile.Name Next sFile Set Opic = Nothing Set SFolder = Nothing Set FSO = Nothing End Sub
Sub InsertThumbnails()
Dim fso As Object
Dim folder As Object
Dim file As Object
Dim row As Integer
Dim picPath As String
' Set the folder path containing the images
picPath = "!pictest/"
' Create FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(picPath)
' Start inserting from row 1
row = 1
' Loop through each file in the folder
For Each file In folder.Files
' Check if the file is an image (you can add more extensions if needed)
If LCase(Right(file.Name, 4)) = ".jpg" Or LCase(Right(file.Name, 4)) = ".png" Then
' Insert the image
ActiveSheet.Pictures.Insert(file.Path).Select
' Resize the image
Selection.ShapeRange.LockAspectRatio = msoTrue
Selection.ShapeRange.Height = 50 ' Adjust this value to change thumbnail size
' Move the image to the correct cell
Selection.Top = ActiveSheet.Cells(row, 1).Top
Selection.Left = ActiveSheet.Cells(row, 1).Left
' Write the file name in the adjacent cell
ActiveSheet.Cells(row, 2).Value = file.Name
' Adjust row height
ActiveSheet.Rows(row).RowHeight = 55 ' Slightly larger than thumbnail height
' Move to the next row
row = row + 1
End If
Next file
' Clean up
Set file = Nothing
Set folder = Nothing
Set fso = Nothing
End Sub
Sub InsertPictures()
Dim SFolder As Object, FSO As Object, Opic As Object
Dim sFile As Object, RngCnt As Integer
Dim ws As Worksheet
Const TILDE As String = "~"
Set ws = ActiveSheet ' or a specific sheet
Set FSO = CreateObject("Scripting.FileSystemObject")
'Where the pictures are. Change to suit
Set SFolder = FSO.GetFolder("C:\testfolder") 'Users\User\Pictures\")
For Each sFile In SFolder.Files
If Left(sFile.Name, 1) <> TILDE Then
RngCnt = RngCnt + 1
Set Opic = Application.ActiveSheet.Shapes.AddPicture(SFolder.Path & "\" & sFile.Name, False, True, 1, 1, 1, 1)
Opic.Left = ws.Range("A" & RngCnt).Left
Opic.Top = ws.Range("A" & RngCnt).Top
Opic.Width = ws.Range("A" & RngCnt).Width
Opic.Height = ws.Range("A" & RngCnt).Height
ws.Range("B" & RngCnt).Value = sFile.Name
End If
Next sFile
Set Opic = Nothing
Set SFolder = Nothing
Set FSO = Nothing
End Sub