Getting image size in VBA?

In the text document in which I created the VBA code, I need to be able to display images in a custom form, as well as resize the custom form to fit any image they render.

I was very confused when I tried to do something similar in the Immediate Box (the image file is actually only 675 pixels wide):

? LoadPicture("C:\Users\arose\Desktop\Security Control Doc\Images\AC1.bmp").Width 17859 

In the end, I found that this is due to VBA using some units besides pixels. Twips, or something like that. But I really need to have image sizes in pixels, so I retired, found roughly what the conversion factor is, and I use this:

 Function TwipsToPixels(Twips As Long) As Long TwipsToPixels = Twips / 25.477 End Function 

It helped, but it is not particularly accurate. So my question is: does anyone have a more elegant and accurate way to get image sizes in VBA?

+4
source share
1 answer

The default unit of measure in VBA twips is a screen-independent unit of 1/20 dots, or 1 / 1,440 inches. There are 567 twins in centimeter.

Pixels are screen-dependent units, so the two functions / properties of TwipsPerPixelX and TwipsPerPixelY should do the trick.

+7
source

Source: https://habr.com/ru/post/1432487/


All Articles