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?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Iban Arriola
  • 2,526
  • 9
  • 41
  • 88

4 Answers4

5

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.

Aaron Thomas
  • 5,054
  • 8
  • 43
  • 89
  • It is not a solution but at least I have an explanation of why is not working... thanks! – Iban Arriola Sep 13 '13 at 07:46
  • I found a workarround in chapter 8 of [RibbonX](http://www.wiley.com/go/ribbonx). It recommends using Window's GDI+ API to load the PNG. There should be some helpful code in the download files for the book. The explination in the book begins on page 274. – robartsd Sep 16 '14 at 19:29
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.

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

Nick
  • 3,454
  • 6
  • 33
  • 56
-1

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.

pjmorse
  • 9,204
  • 9
  • 54
  • 124
Frzorp
  • 1
  • 1