RedditPP Mascot

RedditPP

r/vba • … • u/ThirteenMatt

Paste and select image

Hello everyone, I'm having a problem with something that seems trivial but apparently is not.

I have a piece of code where I paste as picture what is in the clipboard. Next thing I do is give it a name so it can be easily addressed. For this I used the method of "if I just pasted an image, it has the highest shape index in the sheet":

Dim Nom as String, Imag as Shape

Nom = "Image_Name"

ActiveSheet.Pictures.Paste Set Imag = ActiveSheet.Shapes(ActiveSheet.Shapes.Count) Imag.Name = Nom

Problem: the image you paste does not actually always get the highest index for some reason. I have drop down lists in the sheet and by placing a `Debug.Print` `Imag.Name` just after the `Set Imag`, I realised the highest index shape tends to be one of those.

I googled another idea but I only found what I was already doing or people suggesting that the image is automatically selected after pasting so I could just do `Set Imag = Selection`, but that is not true in my case.

Is there a solution to rename the image as you paste it? Or a more foolproof solution to finding the image you just pasted?

— 0