VBA Insert picture is not working with .PNG file

Manith

New Member
Joined
Apr 14, 2020
Messages
29
Office Version
  1. 2016
Platform
  1. Windows
Dear All,

I have the code below, however it is working only with .jpg format. Could you pls help me as I also want it to work with .png format.
Thank you!

--------------------------------

Public Function showpicture(style As String, Optional path As String) As String

If path = "" Then
path = "E:\CKUA\PICTURES"
End If
path = path & "\"


Dim AC As Range

Static P As Shape

On Error GoTo Done


Application.Volatile

Set AC = Application.Caller

PicFile = path & style & ".jpg"

If Not (PicExists(P)) Then

sheetname = Application.Caller.Parent.Name
workbookname = Application.Caller.Parent.Parent.Name
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
VBA Code:
PicFile = path & style & ".jpg"  '<- this line only looks for files with a .jpg extension, which means it won't work for .png files.

If Not (PicExists(P)) Then

See if this works for you. Frankly, I don' t know how your code works. It's incomplete and doesn't make sense to me. However, if it works for you, then, the following modification might work.
VBA Code:
PicFile = path & style & ".jpg"

If Not (PicExists(P)) Then         '<- Insert this and the following two lines

PicFile = path & style & ".png"

End If

If Not (PicExists(P)) Then
 
Upvote 0

Forum statistics

Threads
1,223,247
Messages
6,171,004
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top