Stop "The linked image cannot be displayed" message from showing on screen,

DannyDont

New Member
Joined
Mar 7, 2014
Messages
40
This message appears whenever I attempt to insert an image that does not exist. This I would expect except until recently it did not display. I would like to know how I can stop this error message from being displayed. I apologize as I do not know how to include code in a message so I will copy and paste.
VBA Code:
    If Pref_DC_Special = "Y" Then
        Image_Column1 = Range("A" & Control_Row_Value - 3)
        Image_Column2 = Range("B" & Control_Row_Value - 1)
        Range("A" & Control_Row_Value - 3 & ":" & "B" & Control_Row_Value - 1).Merge
        Range("A" & Control_Row_Value - 3 & ":" & "B" & Control_Row_Value - 1).Select
...
    Selection.Value = ""
    Control_Row_Height = Selection.RowHeight                        'Save to reset original height if no image
    Image_Width_Cell = Selection.Width
    Image_Height_Cell = Selection.Height
    UTY_Ans = Pref_Image_Directory & "\" & ToShow_Img & ".JPG"
Debug.Print UTY_Ans
    On Error GoTo Process_Image_Err
'        Application.ScreenUpdating = False
'        Application.DisplayAlerts = False
    ActiveSheet.Pictures.Insert(UTY_Ans).Select        NOTE: This code looks a bit off but has not been changed and works for all "found" images.
'        Application.ScreenUpdating = True
'        Application.DisplayAlerts = True
    On Error GoTo 0
    Selection.ShapeRange.Height = Image_Height_Cell - 2
    If Selection.ShapeRange.Width > Image_Width_Cell Then Selection.ShapeRange.Width = Image_Width_Cell - 2
'   ======================================================
'   Code below is to get info to center the image in its space
'   ======================================================
    Image_Width_Image = Selection.ShapeRange.Width
    Image_Height_Image = Selection.ShapeRange.Height
    If Image_Height_Image + 5 > Control_Row_Height Then
        Image_Height_Cell = Image_Height_Cell + 5
        Rows(Control_Row_Value).RowHeight = Image_Height_Cell
    End If
    Image_Position_Right = (Image_Width_Cell - Image_Width_Image) / 2
    Image_Position_Down = (Image_Height_Cell - Image_Height_Image) / 2
    Selection.ShapeRange.IncrementLeft Image_Position_Right
    Selection.ShapeRange.IncrementTop Image_Position_Down
    Exit Sub
...
Here is a snapshot of the output.
1650384232659.png

Previously, I simply added the "Image Not Found" in the merged area reserved for the image. Thanks for any help you might provide. I am wondering if something has changed with the process of handling shapes or images?

I hope I have done this properly.
 
Last edited by a moderator:

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
You click vba button on posting toolbar then paste in your code with proper indentation. At least I think that's what you're referring to about doing something properly. Usual approach would be to trap the error number if you can't avoid it otherwise. You should always provide the error number as well as the text description because of them have the same number but different text. Besides, the number is the best way to trap errors. Also strongly advise to show which line causes that error. So replace ### below with your error number.
suggest that before this
VBA Code:
If Pref_DC_Special = "Y" Then
put
VBA Code:
On Error GoTo errHandler
'the rest of your code here...
'up to just before Exit Sub where you'd put

exitHere:
Exit Sub
after Exit Sub
VBA Code:
errHandler:
If Err.Number = ### Then
  'do what? If exit with a message:
  Msgbox "Error " & Err.Number & ": " & Err.Description
  Resume exitHere
Else
  'do something else
End If

End Sub

you don't seem to have a Process_Image_Err so comment out that line?
 
Upvote 0
I did not include the Process_Image_Err routine as VBA never gets to the error routine. I should have included it. Because the Error Trap is never executed, I am not sure what you have suggested will work. I will try it and I have also added my error trap routine. What is also interesting is on the next Image, the Red X Box appears even though the image is found and printed. You can see that in the next image after the entry where the Red X box is more visible. In the "old world", before this began, I would get the "Car Image-NOT FOUND" in the space reserved for the image.

I use this same routine in another similar application. I will run that and see what happens. I have a bit of a longer story to tell but will wait on that as it may not be of any value.

Thank you for your feedback. and thanks for the VBA Code tip. Hopefully, the code looks as it should now. I will update later today.

VBA Code:
Process_Image_Err:
        Application.ScreenUpdating = True
        Application.DisplayAlerts = True

    If Pref_DC_Special = "Y" Then
        Range("A" & Control_Row_Value - 3 & ":" & "B" & Control_Row_Value - 1) = "Car Image-NOT FOUND"
        Rows(Control_Row_Value).RowHeight = Control_Row_Height                        'Reset Row to normal height
    Else
        Range(Pref_Image_Column1 & Control_Row_Value & ":" & Pref_Image_Column2 & Control_Row_Value).UnMerge
    Range(Pref_Image_Column1 & Control_Row_Value) = Image_Column1
    Range(Pref_Image_Column2 & Control_Row_Value) = Image_Column2
    End If
 
Upvote 0
I just ran the other app that has been running for years. It NOW gets the same results when no image is found. I then went back to the app that I was working on. I ran it and stepped through the code in the areas we are discussing. When it executes the line (ActiveSheet.Pictures.Insert(UTY_Ans).Select), it goes directly to the very next statement in the VBA, I have even changed the On Error Goto 0 to On Error Goto Process_Image_Err and it just goes on to the next line of code. I believe that either something has changed in Excel or my settings in Excel or something has changed in WIN 10. I always update office and WIndows and have no idea when the last update took place. The reason that I make the previous statement is that this code has been running for several years. I will include the entire Sub Process_Image() subroutine. I am leaving my comments in. You will see that I have taken a couple of different approaches. Here is the entire subroutine.
VBA Code:
'   ********************************************************
'   ********************************************************
'   *                   Process_Image                      *
'   ********************************************************
'   *                    As Of 04/10/18                    *
'   ********************************************************
'   ********************************************************
  Sub UTY_Process_Image()
    If Pref_Test_Run = "Y" Then
        Debug.Print "UYT_Process_Image"
        Stop
    End If
'   =============================================
'   Check Images Directory path name
'   =============================================
    If Pref_Image_Directory = "" Then
        UTY_Folder_Picker
    End If
'   ================
'   Need to use the Column Variable for Type and Road ... and Color???
'   ===================================================
    If Pref_DC_Special = "Y" Then
        Image_Column1 = Range("A" & Control_Row_Value - 3)
        Image_Column2 = Range("B" & Control_Row_Value - 1)
        Range("A" & Control_Row_Value - 3 & ":" & "B" & Control_Row_Value - 1).Merge
        Range("A" & Control_Row_Value - 3 & ":" & "B" & Control_Row_Value - 1).Select
    Else
        Image_Column1 = Range(Pref_Image_Column1 & Control_Row_Value)
        Image_Column2 = Range(Pref_Image_Column2 & Control_Row_Value)
        Range("C" & Control_Row_Value & ":D" & Control_Row_Value).Merge
        Range(Pref_Image_Column1 & Control_Row_Value & ":" & Pref_Image_Column2 & Control_Row_Value).Select
    End If
    Selection.Value = ""
'    Range("C" & Control_Row_Value).Select
    Control_Row_Height = Selection.RowHeight                        'Save to reset original height if no image
'    Rows(Control_Row_Value).RowHeight = Pref_Image_Row_Height       '??? for New Page Break Routine
    Image_Width_Cell = Selection.Width
    Image_Height_Cell = Selection.Height
'    GetPic
'   ***************************************
'   This needs to change so that the
'   directory is same level as csvManifests
'   The directory for images csvImages
'   Need to be at the same level as the
'   folder that contains the MC application
'   This is 'normally' csvManifests or
'   csvSwitchlists
'   ***************************************
'    With CreateObject("Scripting.FileSystemObject")
    UTY_Ans = ActiveWorkbook.Path
'        UTY_Ans = .GetParentFolderName(Application.ActiveWorkbook.Path)
Debug.Print UTY_Ans
    'End With
'Stop
    UTY_Num = InStr(1, UTY_Ans, "csvManifests")
'    UTY_Ans = Left(UTY_Ans, UTY_Num - 1)
Debug.Print UTY_Ans
    UTY_Ans = UTY_Ans & "\csvImages\" & ToShow_Img & ".JPG"
'Debug.Print ("E:\OneDrive\Documents\Operations\DansManifestCreator\csvImages\" & ToShow_Img & ".JPG")
'UTY_Ans = "E:\OneDrive\Documents\Operations\DansManifestCreator\csvImages\" & ToShow_Img & ".JPG"
Debug.Print UTY_Ans
    On Error GoTo Process_Image_Err
        Application.ScreenUpdating = False
        Application.DisplayAlerts = False
    ActiveSheet.Pictures.Insert(UTY_Ans).Select
'ActiveSheet.Pictures.Insert("E:\OneDrive\Documents\Operations\DansManifestCreator\csvImages\" & ToShow_Img & ".JPG").Select
'Stop
'    ActiveSheet.Pictures.Insert(UTY_Ans & "\csvImages\" & ToShow_Img & ".JPG").Select
'    ActiveSheet.Pictures.Insert(CSVFile_File_Path & "\csvImages\" & ToShow_Img & ".JPG").Select
        Application.ScreenUpdating = True
        Application.DisplayAlerts = True
    On Error GoTo 0
    Selection.ShapeRange.Height = Image_Height_Cell - 2
    If Selection.ShapeRange.Width > Image_Width_Cell Then Selection.ShapeRange.Width = Image_Width_Cell - 2
'   ======================================================
'   Code below is to get info to center image in its space
'   ======================================================
    Image_Width_Image = Selection.ShapeRange.Width
    Image_Height_Image = Selection.ShapeRange.Height
    If Image_Height_Image + 5 > Control_Row_Height Then
        Image_Height_Cell = Image_Height_Cell + 5
        Rows(Control_Row_Value).RowHeight = Image_Height_Cell
    End If
    Image_Position_Right = (Image_Width_Cell - Image_Width_Image) / 2
    Image_Position_Down = (Image_Height_Cell - Image_Height_Image) / 2
    Selection.ShapeRange.IncrementLeft Image_Position_Right
    Selection.ShapeRange.IncrementTop Image_Position_Down
    Exit Sub
'
Process_Image_Err:
        Application.ScreenUpdating = True
        Application.DisplayAlerts = True

    If Pref_DC_Special = "Y" Then
        Range("A" & Control_Row_Value - 3 & ":" & "B" & Control_Row_Value - 1) = "Car Image-NOT FOUND"
'        Range("A" & Control_Row_Value - 3 & ":" & "B" & Control_Row_Value - 1) = ToShow_Img & "-NOT FOUND"
        Rows(Control_Row_Value).RowHeight = Control_Row_Height                        'Reset Row to normal height
    Else
        Range(Pref_Image_Column1 & Control_Row_Value & ":" & Pref_Image_Column2 & Control_Row_Value).UnMerge
'    Range("C" & Control_Row_Value & ":D" & Control_Row_Value).UnMerge
'    Selection.RowHeight = Control_Row_Height                        'Reset Row to normal height
    Range(Pref_Image_Column1 & Control_Row_Value) = Image_Column1
'    Range("C" & Control_Row_Value) = ToShow_Typ
    Range(Pref_Image_Column2 & Control_Row_Value) = Image_Column2
'    Range("D" & Control_Row_Value) = ToShow_Rod
    End If
End Sub
I can send everything you need to run the app. The folder size is 749 MB

Thanks for everything.
 
Upvote 0
I can't see why it would just continue, unless you have previously disabled error handling (On Error GoTo 0 will do that) or disabled warnings/alerts perhaps. There are at least 2 external calls that I can see in that code, so it can't even be copied and tested by anyone in their own workbook. Regardless, in that code I see no initialization of an error handler before you attempt to insert the image, and that's what I suggested you try. That code doesn't set the error handler until after that:
On Error GoTo Process_Image_Err
and then you disable error handling with
On Error GoTo 0

Note the explanation for this here:
 
Upvote 0
I can't see why it would just continue,
To that I would add "or failure doesn't generate an error" but that seems unlikely.
 
Upvote 0
I have highlighted the line that causes the "little" red box (see the image in a previous post). (I did not include the error-handling routine as it is also shown in previous posts.
VBA Code:
    On Error GoTo Process_Image_Err
        Application.ScreenUpdating = False
        Application.DisplayAlerts = False
   [COLOR=rgb(226, 80, 65)] [/COLOR][SIZE=5][B][COLOR=rgb(226, 80, 65)]ActiveSheet.Pictures.Insert(UTY_Ans).Select[/COLOR][/B][/SIZE]
        Application.ScreenUpdating = True
        Application.DisplayAlerts = True
    On Error GoTo 0
I believe that I have set the Error Handler in the first line above. When I step through the code, the error occurs on the line in RED and then the code goes to the very next line. I understand that it does not make sense. I then unset the Error Handler in the last line above. What is interesting to me is, if you look at the output sample in my second post, the Error is displayed in the rows below the first occurrence even though there is an Image????? You need to look at it closely as the image covers up most of the Box with the little Red X. NOTE: Each input record from a CSV file creates four rows of output. So when looking at the sample output, you need to look at it in steps of four rows at a time. (Hope that makes sense). As I indicated previously, I can make the necessary files available. This consists of 1. the Application(192 KB), 2. a Preferences File(117 KB), 3. a CSV File(6 KB), and 4. the folder of images(each image is in the 250KB range). I can reduce the number of images to five or six so the folder of images because very small.

I am busy this morning but will work on getting the necessary files on OneDrive or Google Drive or ???

As I mentioned previously, I use similar code in another application that has taken the Error Handler in the past. Now it too does not and the same line as in RED causes the same issue. That is why I mentioned that I am thinking something has changed in my Excel settings or in Windows 10 itself.

I do understand how hard it is to decipher someone's code and I really appreciate all of your efforts!!!!! This is why I suggest providing all things necessary to run this on your own machine(s).
THANK YOU ALL,
Dan
 
Upvote 0
I guess that's the only option left at this point. Try to keep the size down by cutting out sheets/images/etc. that are not required.
 
Upvote 0
I have placed the required files on Google Drive. Here is the link. When you download, which you must because you can't run Macros in the Cloud, a zip file will be created and downloaded. Extract things to one directory. You can call it whatever but its normal name is csvManifests. Here is the link:
https://drive.google.com/drive/folders/1QHyrwfbp5m-tSMIMWMGtN_WEPfp3Ox6f?usp=sharing
This will take you inside the csvManifests directory. When testing, I selected csvManifest from the header area on the screen and performed the download from there. All the files and folders go into one high-level directory as described above. The total size of the data required is 4.3 MB or smaller as Google Drive will create a Zip file for the download.

The application is MC3-4JMRI-6.02B-DCVersion-4by.xlsm. It will open the application's Main Menu. Begin by selecting Create Manifest. The first time you begin, the app will have you select the directory that contains the images. This will be csvImages within the base folder. It will only ask the first time. Next, it will have you select the CSV file to process. There is only one to select. There are some unusual things that can occur. The primary one is that if you stop execution in mid-steam you will want to select VIEW from the Excel menu bar and unhide the Preference file and close it. This file is used in the background. If you forget to do this, things could get a bit messed up. If this happens, just download the stuff again. I have stop statements and debug statements throughout so you can step through code with F5 or F8. These are here in an attempt to determine the issue.

I am open to helping in any way I can. We could do a TeamViewer session if you like.

Anyone that is looking at this topic is free to download the files and have a go at it.

Thanks for all the help.
 
Upvote 0
This is going to take a while and I may not be successful.
Blocks on files need to be removed because of Windows. I have to examine your code first to see what it might do to my pc or app settings. F'rinstance, you're invoking methods such as ChDrive and altering the state of app windows. The latter may make editing difficult or even impossible (e.g. perhaps my ribbon will disappear). I'll see what I can do.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,198
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top