Search code examples
excelvbaimagecontrolsuserform

Rotated images with userform


i have a big problem and I need your help. I have a program with Excel and I use a Userform with an Image control. When I add images to this control, most of times, images are being rotated.

I need the images to be uploaded as they are.

Thank you in advance

I tried fixing various options for the Image control. Images are, most of times, being rotated.


Solution

  • I looked at your file (edit: link to file in original question since removed), but the image control didn't contain any image to see what you tested with.

    Regardless of that my suspicion is that your problem doesn't lie with the image control, but with the images themselves. The file browse filter you use makes the user select jpg files, but jpg files have extra meta data in them (exif) that tells any application handling them what their orientation should be. If you take a photo with your camera in portrait mode, the image data might still be in landscape mode, but the exif data says to e.g. rotate 90 degrees left. But the VBA control is probably ignoring this exif data, which makes some images turn out 'rotated'.

    Testing this with 2 jpgs on my system I can confirm that VBA indeed ignores the exif data and doesn't appropriately rotate the image when displaying it. You thus need to adjust the jpg files themselves to fix this; e.g. Irfanview has lossless jpg rotation functionality built in.

    Doing this programmatically is of course also possible, but that is a whole other question which might be irrelevant if manually rotating the jpgs themselves fixes this issue for you. You can already look for inspiration by googling "vba rotate jpg"; this StackOverflow post is a good starting point I think (look at the 2nd answer).