I have code that has been working, and all of the sudden it is not. I have tried everything and cannot figure out why. It works when I do a step by step (F8) but not when I run the code. What the code is doing is finding an ID in column B, and finding the jpg that has the same image (in the file H:\Images...) and pasting it into the 1st column. The code produces the error "Run-time error 1004: PasteSpecial method of worksheet class failed" and highlights the ActiveSheet.PasteSpecial line. Please help!
Sub Picture()
Dim picname As String
Dim lThisRow As Long
lThisRow = 3
Do While (Cells(lThisRow, 2) <> "")
Cells(lThisRow, 1).Select 'This is where picture will be inserted
picname = Cells(lThisRow, 2) 'This is the picture name
'MsgBox (picname)
Dim DirFile As String
DirFile = "H:\Images\9 Thumbnails\" & picname & ".jpg"
If Len(Dir(DirFile)) = 0 Then
'MsgBox "File does not exist"
Else
ActiveSheet.Pictures.Insert("H:\Images\9 Thumbnails\" & picname & ".jpg").Select
Selection.Cut
ActiveSheet.PasteSpecial Format:="Picture (JPEG)", Link:=False, _
DisplayAsIcon:=False
'Set WB = Workbooks.Open(DirFile)
With Selection
.ShapeRange.ScaleHeight 0.9, msoTrue
.Left = Cells(lThisRow, 1).Left + Cells(lThisRow, 1).Width / 2 - Selection.ShapeRange.Width / 2
.Top = Cells(lThisRow, 1).Top + Cells(lThisRow, 1).Height / 2 - Selection.ShapeRange.Height / 2
'.ShapeRange.LockAspectRatio = msoFalse
''.ShapeRange.Width = 80#
.ShapeRange.Rotation = 0#
End With
End If
lThisRow = lThisRow + 1
Loop
Range("B3").Select
On Error GoTo 0
Application.ScreenUpdating = True
Exit Sub
End Sub