VBA to Insert Pictures into the Cell based on the value in another coln.

OzPanda

New Member
Joined
Mar 1, 2012
Messages
19
Hey guys

Can someone please help me fix up my VBA code ? :'(

Here is my current code:

Code:
Sub PlacePics()    Dim Path As String, Pics As Range, Pic As Range, Pix As Picture
    
    On Error Resume Next
    
    Path = "C:\Users\Panda\Pictures\"
    Set Pics = ActiveSheet.Range("A9:A504")
       
    
    For Each Pic In Pics
        Pic.Offset(0, 1).Select
        Set Pix = ActiveSheet.Pictures.Insert(Path & Pic.Value & ".jpg").Select
        With Pic
            .ShapeRange.LockAspectRatio = msoFalse
            .Left = ImageCell.Left
            .Top = ImageCell.Top
            .Width = ImageCell.Width
            .Height = ImageCell.Height
        End With
    Next Pic
End Sub

Basically I would like to insert jpg images into coln B from a folder. The names of the pictures are based in the text values in coln A.

That is currently working however I would like to make 2 improvements.

Improvement 1 is if the image doesn't exist skip it. (At the moment I have the resume next but I hear this isn't good coding)

Improvement 2 which is the main issue:

The images are different sizes some are way too big. I would like to insert it into the cell and make the height of the cell be the limiting factor and scale it to scale (aspect ratio)?

Can someone please help?
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,214,375
Messages
6,119,168
Members
448,870
Latest member
max_pedreira

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