• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

An error occurred while importing this file - Blank .png [EXCEL]

b18m

New Member
Hi everyone. I'm a bit of a novice in VBA, but bootlegged together an application to build a planogram that uses VBA to pull in product photos of bottles/cans. I hit the escape key about 200 times before finally coming here. I'm receiving this error when copying the tab: "An error occurred while importing this file. C:\Users\myname\Documents\filename\images\.png". I thought I could create a blank file in that folder, but no can do. Tried adding "On Error Resume Next" but clearly wasn't adding to the right place. If I hit escape enough times it works, but that clearly isn't the correct way to learn it. This is the broken code. The line where it says the error is is right after "'Resize picture to best fit the range". I've seen some posts about this, but the troubleshooting didn't work. Appreciate whoever can help so much!!! Happy to send file for some help!

Code:
Option Explicit

Public Function PictureLookupUDF(FilePath As String, Location As Range, Index As Integer)
On Error Resume Next


Dim lookupPicture As Shape
Dim sheetName As String
Dim pictureName As String

pictureName = "PictureLookupUDF"

''Dim picTop As Double
''Dim picLeft As Double

sheetName = Location.Parent.Name

'Delete current picture with the same Index if exists
For Each lookupPicture In Sheets(sheetName).Shapes
If lookupPicture.Name = pictureName & Index Then
lookupPicture.Delete
End If
Next lookupPicture

'Add the picture in the right location
Set lookupPicture = Sheets(sheetName).Shapes.AddPicture _
(FilePath, msoFalse, msoTrue, Location.Left, Location.Top, -1, -1)

'Resize picture to best fit the range
If Location.Width / Location.Height > lookupPicture.Width / lookupPicture.Height Then
lookupPicture.Height = Location.Height

Else

End If

'change the picture name
lookupPicture.Name = pictureName & Index

PictureLookupUDF = "Picture Lookup: " & lookupPicture.Name

End Function
 
b18m
Why do You need to try to import that?
Have You tried to write to Your browser same ( C:\Users\myname\Documents\filename\images\.png )?
... do it work?
On Error Resume Next is in correct place...
... but there are missing action - it that needs to work.
 
b18m
Why do You need to try to import that?
Have You tried to write to Your browser same ( C:\Users\myname\Documents\filename\images\.png )?
... do it work?
On Error Resume Next is in correct place...
... but there are missing action - it that needs to work.

Hi, what do you mean write to my browser? How I have it set up is that you enter the product in one cell and then there are cells below with a formula that say based on that product name (D11), the Folder path ($D$2) and the file extension ($D$4), it pulls the image into the intended cell (COLUMN(D4)&ROW(D4)

=PictureLookupUDF('Product List'!$D$2&D11&'Product List'!$D$4,D4,COLUMN(D4)&ROW(D4))
 
b18m
Browser: I'm using Chrome and if You paste Your ... given ... file to it and press < ENTER > ... do it works?
Screenshot 2022-06-13 at 19.37.04.png

Without a sample Excel-file - maybe someone else could continue.
 
Back
Top