简体   繁体   中英

Excel, create image's thumbnail with macro and sort

I have an excel file with a column that contains the full path of images. I have created a column with the thumbnails of each image using the following macro:

Sub InsertPicFromFile()
Dim cCell As Range
For Each cCell In Selection
If cCell.Value <> "" Then
On Error Resume Next
ActiveSheet.Shapes.AddPicture _
    Filename:=cCell.Value, LinkToFile:=msoFalse, _
    SaveWithDocument:=msoTrue, _
    Left:=cCell.Offset(ColumnOffset:=1).Left, Top:=cCell.Top, _
    Width:=cCell.Height, Height:=200
End If
Next cCell
End Sub

It works fine but I cannot sort any rows as these images are not "inside" a cell (or something like that). basically the images are not order based on the parent row.

I don't know if is possible, but is there any alternative way to creare a thumbnail in excel?

In order to sort the images, you will need to ensure each image is within their relevant cell boundary. You can accomplish this by ensuring the image size (width/height) is equal or smaller than their holding cell. In your code, you will need to change your last statement of your code to the below :-

Width:=cCell.Offset(0, 1).Width, Height:=cCell.Height

You can then perform sorting based on the parent rows.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM