Sub AddOlEObject1()
Dim mainWorkBook As Workbook
Application.ScreenUpdating = False
Set mainWorkBook = ActiveWorkbook
Sheets("Sheet1").Activate 'Change the sheet name from "Sheet1" to the sheet name where you want your pictures to go
'Cleanoff Sheet1
ActiveSheet.UsedRange.ClearContents
For Each sh In Sheets("Sheet1").Shapes
sh.Delete
Next sh
'Change the folderpath to wherever your pictures are coming from
Folderpath = InputBox("Enter the complete folder path to you files" & Chr(13) & " in this format: 'C:\Users\you\folder1'")
Set fso = CreateObject("Scripting.FileSystemObject")
NoOfFiles = fso.GetFolder(Folderpath).Files.Count
Set listfiles = fso.GetFolder(Folderpath).Files
For Each fls In listfiles
strCompFilePath = Folderpath & "\" & Trim(fls.Name)
If strCompFilePath <> "" Then
If (InStr(1, strCompFilePath, "jpg", vbTextCompare) > 1 _
Or InStr(1, strCompFilePath, "jpeg", vbTextCompare) > 1 _
Or InStr(1, strCompFilePath, "png", vbTextCompare) > 1) Then
counter = counter + 1
If counter <= NoOfFiles / 3 Then
If counter = 1 Then counter1 = 1
If counter > 1 Then counter1 = counter1 + 3
Sheets("Sheet1").Range("B" & counter1 + 1).Value = fls.Name
Sheets("Sheet1").Range("B" & counter1).ColumnWidth = 27 'Adjust COLUMNS to fit your pictures
Sheets("Sheet1").Range("B" & counter1).RowHeight = 80 'Adjust ROWS to fit your pictures
Sheets("Sheet1").Range("B" & counter1).Activate
Call insert1(strCompFilePath, counter1)
Sheets("Sheet1").Activate
End If
If counter > NoOfFiles / 3 And counter <= NoOfFiles * 2 / 3 Then
counter2 = counter - Application.Round(NoOfFiles / 3, 0)
If counter2 > 1 Then counter2 = 3 * counter2 - 2
Sheets("Sheet1").Range("D" & counter2 + 1).Value = fls.Name
Sheets("Sheet1").Range("D" & counter2).ColumnWidth = 27 'Adjust COLUMNS to fit your pictures
Sheets("Sheet1").Range("D" & counter2).RowHeight = 80 'Adjust ROWS to fit your pictures
Sheets("Sheet1").Range("D" & counter2).Activate
Call insert2(strCompFilePath, counter2)
Sheets("Sheet1").Activate
End If
If counter > NoOfFiles * 2 / 3 Then
counter3 = counter - Application.Round(NoOfFiles * 2 / 3, 0)
If counter3 > 1 Then counter3 = 3 * counter3 - 2
Sheets("Sheet1").Range("F" & counter3 + 1).Value = fls.Name
Sheets("Sheet1").Range("F" & counter3).ColumnWidth = 27 'Adjust COLUMNS to fit your pictures
Sheets("Sheet1").Range("F" & counter3).RowHeight = 80 'Adjust ROWS to fit your pictures
Sheets("Sheet1").Range("F" & counter3).Activate
Call insert3(strCompFilePath, counter3)
Sheets("Sheet1").Activate
End If
End If
End If
Next
'mainWorkBook.Save
Application.ScreenUpdating = True
End Sub
Function insert1(PicPath, counter1)
With ActiveSheet.Pictures.insert(PicPath)
With .ShapeRange
.LockAspectRatio = msoTrue
'.Width = 50 'Adjust to change the WIDTH of your pictures
.Height = 80 'Adjust to change the HEIGHT of your pictures
End With
.Left = ActiveSheet.Range("B" & counter1).Left
.Top = ActiveSheet.Range("B" & counter1).Top
.Placement = 1
.PrintObject = True
End With
End Function
Function insert2(PicPath, counter2)
With ActiveSheet.Pictures.insert(PicPath)
With .ShapeRange
.LockAspectRatio = msoTrue
'.Width = 50 'Adjust to change the WIDTH of your pictures
.Height = 80 'Adjust to change the HEIGHT of your pictures
End With
.Left = ActiveSheet.Range("D" & counter2).Left
.Top = ActiveSheet.Range("D" & counter2).Top
.Placement = 1
.PrintObject = True
End With
End Function
Function insert3(PicPath, counter3)
With ActiveSheet.Pictures.insert(PicPath)
With .ShapeRange
.LockAspectRatio = msoTrue
'.Width = 50 'Adjust to change the WIDTH of your pictures
.Height = 80 'Adjust to change the HEIGHT of your pictures
End With
.Left = ActiveSheet.Range("F" & counter3).Left
.Top = ActiveSheet.Range("F" & counter3).Top
.Placement = 1
.PrintObject = True
End With
End Function
Sub ClrSheetofStuff()
Sheets("Sheet1").Activate 'Change the sheet name from "Sheet1" to the sheet name you want to clear
ActiveSheet.UsedRange.ClearContents
For Each sh In Sheets("Sheet1").Shapes
sh.Delete
Next sh
End Sub