【发布时间】:2016-02-18 15:51:46
【问题描述】:
我正在使用 URL 将图片放在我的工作表中。该代码工作得很好,除了“on error resume next”将前一个单元格的(良好)值放在发生错误的单元格中,而不是它应该的单元格中(一行向上)。然后它继续将值放在它们所属的位置,直到出现另一个错误。
我尝试将“on error resume next”放置在代码的不同区域,但无法解决问题。是错误处理放置在哪里的问题,还是我需要更好的错误处理程序?
谢谢, 安迪
Sub InsertPic()
On Error Resume Next
Dim pic As String
Dim myPicture As Picture
Dim rng As Range
Dim cl As Range
Set rng = Range("F2:F1131")
For Each cl In rng
pic = cl.Offset(0, -1)
Set myPicture = ActiveSheet.Pictures.Insert(pic)
With myPicture
.ShapeRange.LockAspectRatio = msoFalse
.Width = cl.Width
.Height = cl.Height
.Top = Rows(cl.Row).Top
.Left = Columns(cl.Column).Left
End With
Next
End Sub
【问题讨论】:
标签: vba excel error-handling