I developed code to search images from a folder (chosen by the user) and put it in a column in Excel thru some loops.
Now I'm trying to work with multi-dimensional arrays, so it can also insert images into multiple columns. Instead of putting the images inside column A, I'm trying to make a loop so it also inserts the images inside column B.
What I achieved so far:
Sub ReadFolder()
'
'ReadFolder
'
Dim File As Variant
Dim Counter As Long
Dim DirectoryList() As String
Dim varResp As Variant
Dim shape as Excel.shape
ReDim DirectoryList(1000)
' check if the user inserted a valid path or if he canceled the operation and offer him a chance to abort the operation or retry
lblTryAgain:
varResp = InputBox("Type down the files path)", "Path")
If Trim(varResp) = "" Then
If MsgBox("Do you wish to abort?", vbYesNo + vbQuestion, "Abort?") = vbYes Then
GoTo lblExit
Else
GoTo lblTryAgain
End If
Else
File = Dir$(varResp & "\*.*")
If File = "" Then
MsgBox "The path doesnt exist , Please retry", vbExclamation, "Fail"
GoTo lblTryAgain
End If
End If
On Error GoTo Erro
' fill the array with elements that are inside the file(gotta put then into a 2d array with the dimension (n,2)
Do While File <> ""
DirectoryList(Counter) = File
File = Dir$
Counter = Counter + 1
Loop
' resize the array accordingly to the number of elements filled inside it
ReDim Preserve DirectoryList(Counter - 1)
' delete the images inside the sheet before inserting new ones
For Each shape In Worksheets("Sheet1").Shapes
shape.Delete
Next
' loop thru the array and put images into columns A and resize the column, images and rows
For i = 0 To UBound(DirectoryList)
for j = 0 to 1
Debug.Print DirectoryList(i)
With Worksheets("Sheet1").Cells(i+1, j+1)
Set File = Worksheets("Sheet1").Pictures.Insert(DirectoryList(i))
File.Top = .Top
File.Left = .Left
File.ShapeRange.LockAspectRatio = msoFalse
File.Placement = xlMoveAndSize
.ColumnWidth = 30
.RowHeight = 100
File.ShapeRange.Width = 170
File.ShapeRange.Height = 100
End With
next j
Next i
lblExit:
Exit Sub
Erro:
MsgBox "OOpssie, Fail!", vbCritical, "Error"
End Sub
I expect this (considering the folder has only 4 images):

Points to consider:
- The last image has changed because I accidentally deleted it (that doesn't interfere with the problem)
- There is no way to tell how many images the folder is going to have
