Hi guys,
I have the code below in a VB macro. You walk the macro to a folder, it then searches the folder for .jpg or .jpeg files, and adds the name (column 1), photo, and hyperlink (both in column 3) to the table. It runs and places all the photos within the folder in the table (as its own entry), which is fantastic....exactly what I need it to (Thanks to all the help various people in the forum have been nice enough to give me).
The only catch is that when I run it, more times than not, the table isn't in the correct order from top to bottom. I wasn't sure if it was because of how the code searches the folder, or if it has something to do with something else.
Ideally the photos would go down the table ordered by photo name.
Any ideas of how to resolve this issue?
Partial code is below.
For Each pic In fol.Files
If LCase(Right(pic.Path, 4)) = ".jpg" Or LCase(Right(pic.Path, 5)) = ".jpeg" Then
'add row and give reference to it
Set roe = ActiveDocument.Tables(1).Rows.Add
'gives reference to cell 1 then adds photo name
Set cel = roe.Cells(1)
cel.Range.Text = pic.Name
entry = entry + 1
'gives reference to cell 3 then adds pic
Set cel = roe.Cells(3)
'add photo
Set ish = cel.Range.InlineShapes.AddPicture(FileName:=pic.Path, LinkToFile:=False, SaveWithDocument:=True)
'add hyperlink to photo
Set MyLink = ActiveDocument.Range.Hyperlinks.Add(ish, pic.Path, , , "")
End If
Next