excelimagevbaactivex-documents

Have .jpg files within excel when using ActiveX Image Control


I have an excel file with several toggle buttons. When a toggle button is on and the "calculate" command button is pressed, my activeX image frame changes. However, I have all these files in the same directory so I'd have to send the file to my employees zipped. Is there anyway to like maybe load them into the excel workbook on a hidden sheet?

Thank you


Solution

  • I think the LoadPicture() function will look for a system file so you don't want that.

    Add the pictures into images on a worksheet. This way they will be in the workbook.

    enter image description here

    Then right click the image you just added and select properties. Select picture property and navigate to your image file.

    enter image description here

    You can change the name to make sense of your pictures also. So they don't have to be Image1 Image2 etc.

    Then in your code set the picture that you want to change = the image that you want.

    If something
        Image1.Picture = Image2.Picture
    Else
        Image1.Picture = Image3.Picture
    End If
    

    Here Image1 is the picture that changes based on what happens when the calculate button is pressed. Image3 is one of the images that you loaded into the workbook.

    If you are going to store them on some other worksheet you may need to declare a worksheet object and set it to that sheet

    Dim ws As Excel.Worksheet
    Set ws = ActiveWorkbook.Sheets("ImageWorksheet")
    Image1.Picture = ws.Image3.Picture
    

    or something like this may work.

    ActiveWorkbook.Sheets("ImageWorksheet").Image3.Picture
    

    Something like that.