VBA自动载入照片的问题
Sub ZAIRU()
On Error Resume Next
Dim R&
Dim Pic As Object
For Each Pic In Sheet1.Shapes
If Pic.Name <> Sheet1.Shapes("按钮 97").Name Then
Pic.Delete
End If
Next
For R = 3 To Range("B65536").End(xlUp).Row
If (Len(Cells(R, 2)) <> 0) Then
Set Pic = Sheet1.Pictures.Insert(ThisWorkbook.Path & "\图片\" & Cells(R, 2) & ".jpg")
Pic.ShapeRange.LockAspectRatio = True
With Pic.ShapeRange
If .Height / .Width < Cells(R, 1).Height / Cells(R, 1).Width Then
.Width = Cells(R, 1).Width
.Left = Cells(R, 1).Left
.Top = Cells(R, 1).Top + (Cells(R, 1).Height - .Height) / 2
Else
.Height = Cells(R, 1).Height
.Top = Cells(R, 1).Top
.Left = Cells(R, 1).Left + (Cells(R, 1).Width - .Width) / 2
End If
End With
End If
Next R
End Sub
这个自动载入图片的宏,载入图片是可以的,但是如果如果哪一行上对应的图片没有的话,则上边一行的图片就会挪到下边来,比如说,A2中的数据是A,则第一遍for的时候"A.jpg"就载入A1里.然后执行第二遍for,B2里的数据是B,但是如果刚好没有"B.jpg"这张图片,这时候B1里应该是空的,继续执行下次的for,但是实际是A.jpg会落到B1里,A1里成空的了,请问这个问题怎么解决啊?