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!
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