Again usefull and used in the new code but I'm still puzzled about the sorting part.
On my pc and others aswell always the same problem of importing the last selected file first and just then starting at the top of the list.
I adapted your code so that the last selected file is moved to the top of the list. This works fine if every user (not me) selects the first file in the list and then using shift+click the last. The code below can handle this, but if I use ctrl+A then all
is lost. The order of selection isn't respected anymore.
If I look closely at the file open dialog I see the the last clicked file has dotted lines arround it.
Can this be a part of the problem? This dotted line is different when I use ctrl+A or when I use Shift+click.
What I have so far is:
Private Sub InsertPicAndResizeToCell()
'with this macro (using the right mouse button) a picture can be inserted into the active cell
'the picture is resized into the cell keeping ratio
Dim oNewPic As Shape
Dim strAantalPicJumps As Single
Dim stTemp As String
On Error Resume Next
Pic1 = Selection.Address
'Get Pics:
vPics = Application.GetOpenFilename("All image files (*.JPG;*.BMP),*.JPG;*.BMP", Title:="Select the pictures from top to bottom", MultiSelect:=True)
If TypeName(vPics) = "Boolean" Then Exit Sub ' cancelled
'If more than 1 selection is made then use this value to jump
'to the next location at the end of importing the previous picture
'It is important to make a top down selection!!
If UBound(vPics) > 1 Then UserForm3.Show
strAantalPicJumps = UserForm3.cbxFotoJump
'move the last selected picture to the front of the line
I = 1
For J = I + 1 To UBound(vPics)
stTemp = vPics(J)
vPics(J) = vPics(I)
vPics(I) = stTemp
I = I + 1
Next J
'Insert the picture in order:
For I = LBound(vPics) To UBound(vPics)
'Insert the picture:
Set oNewPic = ActiveSheet.Shapes.AddPicture(Filename:=vPics(I), LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, _
Left:=Range(Pic1).Left + 0.5, Top:=Range(Pic1).Top + 0.5, Width:=Range(Pic1).Height, Height:=Range(Pic1).Height)
'Maintain original aspect ratio and set to full size
oNewPic.LockAspectRatio = msoTrue
oNewPic.ScaleHeight factor:=1, RelativeToOriginalSize:=msoTrue
oNewPic.ScaleWidth factor:=1, RelativeToOriginalSize:=msoTrue
'Resize the picture to fit in the destination cells
If (oNewPic.Width / oNewPic.Height) < (Range(Pic1).Width / Range(Pic1).Height) Then
oNewPic.Height = Range(Pic1).Height - 1.5
Else: oNewPic.Width = Range(Pic1).Width - 1.5
End If
'Assign the desired name to the picture
oNewPic.Name = Dir(vPics(I), vbDirectory)
ActiveCell.Range("A1") = Dir(vPics(I), vbDirectory)
'If more than 1 selection of pics is made then jump to next location
If UBound(vPics) > 1 Then
ActiveCell.Offset(strAantalPicJumps, 0).Select
Pic1 = Selection.Address
End If
Next I
End Sub