2

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?

4

4 回答 4

3

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.

于 2013-09-10T16:02:35.593 回答
0

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.

于 2014-10-16T14:44:33.703 回答
0

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.

于 2020-01-09T11:39:56.310 回答
0

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

于 2021-09-01T10:57:45.927 回答