1、VBA代码
Sub ConvertImagePathToEmbeddedImage()
Dim imagePath As String
Dim currentCell As Range
Dim pic As Picture
'将每个行高设置为2厘米
Rows.RowHeight = Application.CentimetersToPoints(2)
For Each currentCell In Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row)
imagePath = currentCell.Value
If imagePath <> "" Then
On Error Resume Next '跳过无效的图片路径
'将图片插入到单元格中
Set pic = ActiveSheet.Pictures.Insert(imagePath)
With pic
.Width = Application.CentimetersToPoints(2) '设置图片宽度为2厘米
.Height = Application.CentimetersToPoints(2) '设置图片高度为2厘米
.Top = currentCell.Top '设置图片上边缘与单元格上边缘对齐
.Left = currentCell.Left '设置图片左边缘与单元格左边缘对齐
.Placement = xlMoveAndSize '将图片嵌入到单元格中
End With
End If
Next currentCell
MsgBox "完美结束"