VBA code for adding JPG image

  • I am trying to create a VBA code for adding JPG image into column A with respect to the Value mentioned in column B. But when ever there is a missing image the whole VBA stops. Is there any way to skip this and move on to the next cell. Thanks in Advance.


  • Ajith M Nair

    Changed the title of the thread from “I am trying to create a VBA code for adding JPG image into column A with respect to the Value mentioned in column B. But when ever there is a missing image the whole VBA stops. Is there any way to skip this and move on to the next cell.” to “I am trying to create a VBA code for adding JPG image into column A with respect to the Value mentioned in column B. But when ever there is a missing image the whole VBA stops. Is there any way to skip this and move on to the next cell. Thanks in Advance.”.
  • Hi Ajith,


    Don't forget to wrap your code in code tags, and read the rules to ensure you get an answer.


    You should just be able to use something like:


    Code
    1. For x = 2 To lastrow
    2. If Dir("\\C:\Users\ajith.nair\Desktop\Range\photos for new range Q1\" & pictname & ".jpg")  = "" Then Goto MyNext
    3. Relevant code
    4. MyNext:
    5. Next x


    Regards

    Justin

  • rory

    Changed the title of the thread from “I am trying to create a VBA code for adding JPG image into column A with respect to the Value mentioned in column B. But when ever there is a missing image the whole VBA stops. Is there any way to skip this and move on to the next cell. Thanks in Advance.” to “VBA code for adding JPG image”.
  • Dear Justin


    Thank you sooo much.

    Could you please attach the whole code.

    I am relatively very new to this VBA and I really cant understand the changes you suggested.

    If possible could you give me the whole new code with your changes.

  • Hi Ajith,


    This works on the example you sent, change the directory as appropriate:



    Let me know how you go.


    Justin

  • It should work, did you change the directory in both spots in the code?


    I have changed the code slightly in the attachment so there is only one spot where you need to change the directory. Are the picture files on you local drive? The code will work for a local drive, it should also work for a networked drive, if it is a web address it will probably require completely different code, test the attachment with a local drive and let me know if it works.


    Regards

    Justin

  • The code is working fine.


    But when i try to share it to someone else the images are not displayed. And it shows an error message.


    I noticed that only people who are connected to my server is able to view these attached images.


    Kindly help me find a solution.


    Am attaching the error message here so that u can have a better understanding of my problem.


    I also noticed that the images doesn't show any error message at the receivers end if i "special paste as photo" in each cell individually.

    But I have around 2000 photos to attach which is very tiresome and frustrating.


    Kindly help out.


  • I think the problem is that you are not embedding the pictures. Try this