PeterBunde
New Member
- Joined
- Dec 7, 2016
- Messages
- 45
Fellow sufferers
My below code stalls somewhere between
and
. I am new to errorhandling, I tried to read everything there is, so whats wrong with my code?
The sub should be run about 300 times to get to the end of my VBA code, but it stalls at random instances of running that sub. There is no pattern. I suppose it is the server behind the URLs used that is unstable.
What should I do to get the code to just not insert the pic if something goes wrong?
BW Peter Bunde Hansen
My below code stalls somewhere between
Code:
Debug.Print "Inserting pic from URL " & strShpUrl
Code:
Debug.Print "Inserted pic from URL " & strShpUrl
The sub should be run about 300 times to get to the end of my VBA code, but it stalls at random instances of running that sub. There is no pattern. I suppose it is the server behind the URLs used that is unstable.
What should I do to get the code to just not insert the pic if something goes wrong?
BW Peter Bunde Hansen
Code:
Sub GetShapeFromWeb(strShpUrl As String, rngTarget As Range)
Dim Shp As Shape
On Error GoTo ErrHandler
Debug.Print "Inserting pic from URL " & strShpUrl
If strShpUrl <> "" Then
With rngTarget
With .Parent
.Pictures.Insert strShpUrl
Set Shp = .Shapes(.Shapes.Count)
End With
Shp.Left = .Left
Shp.Top = .Top
End With
Debug.Print "Inserted pic from URL " & strShpUrl
Shp.Select
FitPic
Set Shp = Nothing
End If
Abort_insert_pic:
Exit Sub
ErrHandler:
Debug.Print "GetShapeFromWeb: " & strShpUrl & " - " & rngTarget
Resume Abort_insert_pic
End Sub