Domanda

I am trying to take an image from a folder to check its width after that. To do it I am using the following peace of code:

         Dim pic As IPictureDisp
         Dim var As Variant
         var = "C:\Myfolder\Animage" & animationNum + 1 & ".png"
         pic = LoadPicture(var)

It is giving me "invalid picture" error. I tried also just using the following line:

        width = LoadPicture("C:\Myfolder\Animage" & animationNum + 1 & ".png").width

But it also gave me the same error. How can I load the picture?

EDIT

I try with a jpg image and it works... Does this function some issues with png files?

È stato utile?

Soluzione

From msdn.microsoft.com:

Graphics formats recognized by Visual Basic include bitmap (.bmp) files, icon (.ico) files, cursor (.cur) files, run-length encoded (.rle) files, metafile (.wmf) files, enhanced metafiles (.emf), GIF (.gif) files, and JPEG (.jpg) files.

.png is not supported.

Altri suggerimenti

LoadPicture command does not seem to like filenames greater than 35 characters in length when operating in later versions of Office. I can load a picture to a userform in Windows 7 Office 2010 and it seems to handle any length of filename, but once you move to Windows 10 / Office 2013 onwards if you go over the 35 character length the Err.Description simply says: "Path/Access error".

Limit your filename to 35 chars and you should be fine.

I had the same issue today, on Windows 10 Office 365.

In my case, the jpeg file I needed to add to a user form had been sent to me via Microsoft teams, and windows security had automatically blocked it.

I had to check the unblock checkbox in the attached image, and was then able to add it to a userform.enter image description here

I was searching for this exact issue and found a solution on another site, so I thought I would share it here.

I did not come up with this code, it is from Experts Exchange here: http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_26980514.html

If you import the .bas file you can use LoadPictureGDI() in place of LoadPicture() which converts the picture prior to loading it into your userform or sheet.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top