Zakkair123
New Member
Hello,
I have the following macro in one of my worksheets and the purpose of it is to acquired images from a REMOTE database when changes are made to cell L7 and W7. It used to work perfectly in Excel 2013 with no error message even if the image does not exist. However, since I updated to Excel 2016, the error box "An error occurred while importing this file" appears everytime an image is missing. I have a loop that checks item numbers in a column if they exist, everytime an image is missing, the same error box would pop up...
Is there a way to adjust my code such that the error messages do not appear?
Thanks!
I have the following macro in one of my worksheets and the purpose of it is to acquired images from a REMOTE database when changes are made to cell L7 and W7. It used to work perfectly in Excel 2013 with no error message even if the image does not exist. However, since I updated to Excel 2016, the error box "An error occurred while importing this file" appears everytime an image is missing. I have a loop that checks item numbers in a column if they exist, everytime an image is missing, the same error box would pop up...
Is there a way to adjust my code such that the error messages do not appear?
Thanks!
Code:
'Activate Add_Photo_Move sub whenever cell L7 or W7 is changed.
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("L7")) Is Nothing Then Sheet8.Add_Photo_Move
If Not Intersect(Target, Range("W7")) Is Nothing Then Sheet8.Add_Photo_Move
End Sub
Sub Add_Photo_Move()
Dim i As Double
Dim xPhoto As String
Dim sLocT As String
Dim Item As String
Dim sPattern As String
Dim oPic As Shape, allpic As String
Dim oP As String, ac As Integer, c, t
Dim Pic As Object
i = 11
start_time = Now()
sLocT = "C:\Program Files (x86)\REMOTE\CompressedImages\"
Item = Range("H" & i)
sPattern = sLocT & Item & "*.jpg"
Application.DisplayAlerts = False
Application.EnableEvents = False
Application.ScreenUpdating = False
For Each Pic In ActiveSheet.Pictures
If Pic.Name <> "PNG" Then
Pic.Delete
End If
Application.DisplayAlerts = False
Application.EnableEvents = False
Application.ScreenUpdating = False
Next Pic
On Error Resume Next
Do While Item <> ""
xPhoto = Dir(sPattern, vbNormal)
Range("G" & i).Select
With ActiveSheet.Pictures.Insert(sLocT & xPhoto)
.Left = Range("G" & i).Left
.Top = Range("G" & i).Top
.Height = 60#
.Width = 100#
End With
Range("H" & i).Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, _
Address:=sLocT & xPhoto, TextToDisplay:=xPhoto
xPhoto = Dir
i = i + 1
Item = Range("H" & i)
sPattern = sLocT & Item & "*.jpg"
Loop
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub