+ Reply to Thread
Results 1 to 10 of 10

Refreshing Image links VBA Excel

  1. #1
    Registered User
    Join Date
    07-25-2017
    Location
    England
    MS-Off Ver
    2013
    Posts
    86

    Refreshing Image links VBA Excel

    Hi,
    I am making a sheet where a user enters 8 pictures on a page, the images are inserted using a button with the following code:
    Please Login or Register  to view this content.
    Basically, I am having problems with the images, in that some of the images sometimes give the message "The linked image cannot be displayed. The file may have been moved, renamed or deleted. Verify that the link points to the correct file and location." I get that most of the time due to renaming folders etc. But a couple of times I have had it randomly lose track of images with no explanation. I realised that simply deleting the image and then pressing undo resets the link somehow but don't know how I would do this manually.

    I was basically hoping to find a way to make the links search relative to the excel sheets location. For example, if the image was initially stored in C:\Users\User\Documents\Img1234, but then moved into a new folder S:\SharedFolder\User\JobName\Images\Img1234. The images will always be moved somewhere in the "JobName" folder, normally in the images folder. But just in case, I was thinking maybe to get some module/function to search the whole folder where the excel sheet is saved for the linked Image, to replace the link. The problem is, I don't know if excel stores the path links anywhere that I can access. I have searched all day on the internet and haven't gotten anywhere. Probably my best idea is to store each images file location on another sheet when it is imported and then code for the "Change Picture" function with the associated filename.


    The potential problem with this method is I would want to loop through the images on each worksheet to find any where the links need refreshing an I don't know if there is any way of identifying which ones are broken. I would want this to run every time you open the spreadsheet. Could someone let me know if this is a method that would even work and is it the most efficient method? and if its not could you attempt to point me in the right direction please.

    Thanks in Advance for any responses

  2. #2
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Refreshing Image links VBA Excel

    Wouldn't it be easier to copy the files to a local folder?

  3. #3
    Registered User
    Join Date
    07-25-2017
    Location
    England
    MS-Off Ver
    2013
    Posts
    86
    The files get uploaded to the shared folder because they need to be accessed by other people, this is not something I can change. But surely it doesn't matter anyway, because if I could make it relative it would only be 'thinking' about the final folder
    Last edited by AliGW; 07-11-2019 at 01:42 AM. Reason: Please don't quote unnecessarily!

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,824

    Re: Refreshing Image links VBA Excel

    For example, if the image was initially stored in C:\Users\User\Documents\Img1234, but then moved into a new folder S:\SharedFolder\User\JobName\Images\Img1234.
    This is a bit confusing. However, it does raise a question: is the drive mapping to the S drive the same on all users' machines? I think solving the linking issue rather than writing code to work around it would be the more robust approach.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  5. #5
    Registered User
    Join Date
    07-25-2017
    Location
    England
    MS-Off Ver
    2013
    Posts
    86

    Re: Refreshing Image links VBA Excel

    You mean just make sure everything is kept in the same place relative to the excel sheet when transferred to the shared folder? I would do that, but not only am I giving it to users who are likely to not follow that even if I tell them to, but it seems to occasionally do it randomly anyway even if the files are kept in the exact same places.

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,824

    Re: Refreshing Image links VBA Excel

    Yes, the files MUST be kept in the same place. I doubt it is doing this randomly (sorry to contradict you).

  7. #7
    Registered User
    Join Date
    07-25-2017
    Location
    England
    MS-Off Ver
    2013
    Posts
    86

    Re: Refreshing Image links VBA Excel

    It's not losing track of them randomly exactly, but I once found that one of the images had vanished and come up with that message "The linked image cannot be displayed..." and it immediately came back when I deleted the image and then pressed undo, almost as if it hadn't refreshed the link, rather than lost track of it.

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,824

    Re: Refreshing Image links VBA Excel

    OK, well that aside, you need to resolve the issue of where the images are to be kept first. As stated, the location needs to be the same for all users: the mapped drive needs to be the same, and that bit of the file path will probably need establishing as a variable in the code - the expert coders will advise.

    Get this bit right first, and then troubleshoot any 'random' behaviour.

  9. #9
    Valued Forum Contributor PaulSP8's Avatar
    Join Date
    11-21-2017
    Location
    Chorley, England
    MS-Off Ver
    2013 & 2021
    Posts
    437

    Re: Refreshing Image links VBA Excel

    I agree with Ali, you need the path to be constant - Especially as trying to work with Excel and a Network drive can be a pain. All kinds of problems can arise.

    For starters, I'd recommend on not using the Drive letter (S) and using the network name.

    Most users where I work have the letter G assigned to a shared drive, but some have it as X, Y, or Z - To get round that I use the network name of the drive which looks like \\GPBWFCD0QP\

    It might be that the drive letter S is actually assigned to a subfolder within the network drive, so S might point to \\GPBWFCD0QP\UserSharedFolder\ which you'll need to use.

    Another problem which you might encounter and might not be realising is that if Excel can't find a Network drive location, it'll default to the My Documents folder on the local machine. If you're already using that then you might not be noticing that something is going wrong.

    Other problems can arise if you're trying to use the Excel workbook from a Network drive, problems can arise when setting your folder defaults unless your specific there as well.

    I've had all kinds of fun with this kind of thing in the past :-|

  10. #10
    Registered User
    Join Date
    07-25-2017
    Location
    England
    MS-Off Ver
    2013
    Posts
    86

    Re: Refreshing Image links VBA Excel

    I'm not in a position where I can change any of the network settings and to be honest I don't think I have enough knowledge to start messing about with it anyway. I am pretty sure that all the users have the drive letter as (S). So surely the best cause of action would be to do what I suggested? I have written some code to identify where the workbook is saved, it then considers all the sub folders within the parent folder of the spreadsheet (the images are always going to be in the same folder as the excel file, sometimes there may be subfolders) and searches for the image that is lost. At the moment, this runs on opening the spreadsheet and does it for all images. This is obviously not very efficient. Would anyone know if there is a way for excel to distinguish between images that are there and ones where the link is 'broken' so i could specifically target those ones. If anyone could offer any suggestions I'd really appreciate it Also, if anyone knows how excel refreshes the links behind the image, or knows of any way I can access these links. That'd be great.
    Last edited by georgedixon; 07-12-2019 at 10:22 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Refreshing links to images excel vba
    By georgedixon in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-10-2019, 04:36 AM
  2. Valid Image Links
    By fitkhan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-20-2015, 06:22 AM
  3. Excel 2010 "vlookup pictures vba" links image instead of saving it as an image
    By neverdom in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-28-2013, 04:17 AM
  4. Bloomberg links not refreshing in VBA code
    By cog38 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-20-2013, 11:13 AM
  5. Replies: 3
    Last Post: 08-19-2010, 07:41 AM
  6. Opening Excel workbook without refreshing RTD-links
    By billiboy in forum Excel General
    Replies: 5
    Last Post: 09-11-2009, 10:04 AM
  7. Refreshing links from different workbooks
    By garfield185 in forum Excel General
    Replies: 0
    Last Post: 09-16-2008, 05:01 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1