Is it possible to use PNG images in userforms in 64 bit Excel?

  • Been scouring for hours and have only come across a few threads discussing converting PNG files so they are compatible in userforms but none of them work, possibly because I'm in 64 bit Excel. This one I've gotten to actually not give errors but it still doesn't work: https://www.excelforum.com/exc…-image-into-userform.html . I converted Long to LongPtr and replaced olepro32.dll with oleaut32.dll which was suggested for 64 bit Excel but still no luck despite no longer getting errors. No images will load.


    Wondering if this is a lost cause at this point. Unfortunately it has to be PNG because the API only uses PNG files. All help appreciated.

  • User forms only accept bitmap (.btm) images, however, changing a png file to bitmap before loading it into a user form is possible via VBA using API functions.


    Andy Pope provided a solution here


    https://www.excelforum.com/exc…-image-into-userform.html


    It works on 64 Bit systems

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

    Edited once, last by KjBox ().

  • It works perfectly for me on my 64 Bit system without any modification to the code.


    Maybe it has something to do with the actual image. Can you attach the image here and I will try adding it to the userform in the file Andy created.

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Thanks for that.


    No problem with the image, it loads into the user form perfectly well for me.


    I assume the image downloads ok to your temp folder. Does Andy's code work for a different PNG? If you don't have another PNG image then take a screenshot and save it to your temp folder, screenshots should be .png


    If that does not work then really difficult for me to imagine what could be going wrong for you.

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • No I have not gotten it to work. Adding PtrSafe just prevents me from getting errors when it runs. See my very first post about the changes I've made attempting to get it to work. It looks like GdiplusStartup is returning a bad value or no value at all (I don't see any value) as when I run it the part following is skipped:


  • You're passing pointers/handles around, so they will need to be LongPtr to work on 64bit Office, not Long.

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • You're passing pointers/handles around, so they will need to be LongPtr to work on 64bit Office, not Long.

    Hi Rory, thanks for responding. I have done that. As I mentioned in the first post, I replaced all to LongPtr and that resulted in a runtime error 54, file not found: olepro32.dll. A forum online said that for 64 bit I need replace that code and point to oleaut32.dll which I did. That resulted in no longer getting an error but the image still does not load.

  • I suggest you post the code you have currently for review.

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • UserForm1

    basGDIPlus

    Module1

    Code
    Option Explicit
    
    Sub Button1_Click()
        UserForm1.Show
    End Sub
  • OK, you can't just replace every Long with LongPtr. Only pointers and handles need to be LongPtr. I'll have a detailed look when I have time (or failing that I'll just ask Andy when I see him next week :))

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • OK, you can't just replace every Long with LongPtr. Only pointers and handles need to be LongPtr. I'll have a detailed look when I have time (or failing that I'll just ask Andy when I see him next week :))

    Ah ok hopefully that's the problem. Thanks so much for your help! Crazy (or maybe not?) that you know the author! Small world??


    Also, I'd tried it like this. It also doesn't give me errors but it didn't work which is why I tried changing all of them.


  • Try this for the GDI Plus module:


    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • Glad to help. :)

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!