I am attempting to insert several pictures into an excel spreadsheet, and the save it as a PDF. I have been able to figure out how to space the pictures and iterate through all the pictures in a folder, but I can't seem to figure out how to iterate through the pictures in order.
I have found that I can iterate through the .jpg files in a specific folder using Dir as seen in this question: Loop through files in a folder using VBA? and this question macro - open all files in a folder. It has worked wonders, but I need to iterate through the pictures in order. The pictures are labeled "PHOTOMICS0" with that final number increasing.
Here is what I am working with.
counter = 1
MyFile = Dir(MyFolder & "\*.jpg")
Do While MyFile <> vbNullString
incr = 43 * counter
Cells(incr, 1).Activate
ws1.Pictures.Insert(MyFolder & "\" & MyFile).Select
MyFile = Dir
counter = counter + 1
Loop
So far, MyFile has gone from "PHOTOMICS0" to "PHOTOMICS4", 9, 10, 7, 2, 3, 8, 6, 5, and finally 1. When repeated it follows the same order. How can I increment through these in numerical order?