Inserting an image

killar65

New Member
Joined
Jul 11, 2017
Messages
23
Good morning everyone...hopes this finds all well...

Prob a very easy one to solve...I've checked out Dr. Google but haven't quiet found what i'm looking for...

I have a worksheet called Rocks.
I have a folder on C:\ called rock pics

I would like an image to automatically load into cell B2, based on the contents in cell A2...ie...If the word granite is in cell A2, then I would like the granite image (in C:\rock pics) to automatically display in cell B2.

The picture image needs to be 100 x 100.

Any help would be greatly appreciatted.

Cheers,
James
 
Something does not fit but we can't see from here. I guess you have to troubleshoot from that end.
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Well...I've got it to work to a point.

Went into the trust centre and made some changes there...added the picture folder as a trusted destination etc...

If I go into the VBA editor and press F5 to run the code, it works...image appears fine...for both name with ext and name without code.
Step out of the editor and nothing works.
Running Office professional plus 2021 btw.
 
Upvote 0
Don't know how much difference there is between 2013 prof and yours but you still must have some items to adjust by the sound of it.
Re: "Step out of the editor and nothing works." Does this mean that a Button on your worksheet does not work if you assign the macro to it?
 
Upvote 0
Afternoon Jolivanes,

Apologies for the lateness of my reply...been doing some long, late shifts...

Not sure what I did, but i've managed to get your code working...happy days...many thanks for that...and your patience...greatly appreciatted...

As i've been looking at what I want to do, I was wondering if it was possible to do the following...

In cell B2 is the name of a rock (no extension)...I would like the picture to load underneath sized at 100,100...the next rock name is at D2 etc going up to U2 with pictures loading underneath...

This follows on at B12, D12 etc up to U12 with pictures loading underneath...

Picture location is c:\Rocks and sheet name is Mafic.

Once again, thankyou...

James
 
Upvote 0
You mention B2 (Column 2), D2 (Column 4) next. These Columns are even numbers. Why U2 (Column 21) which is an odd Column?
I assume the names jump by 2 Columns. Changed the "U", which is 21, to "T", which is 20.
Check and change references if and where required.
Code:
Sub Without_Extension_Multiple_Pics_B()
Dim i As Long, j As Long, fn As String, sh1 As Worksheet, filename
Set sh1 = Worksheets("Mafic")
    Application.ScreenUpdating = False
    For j = 2 To 12 Step 10
    For i = 2 To 20 Step 2    '<---- Change 20 to last Column number that has picture names
        fn = Dir("C:\Rocks\" & sh1.Cells(j, i).Value & "*")
        If Not fn = vbNullString Then
            sh1.Shapes.AddPicture _
                filename:="C:\Rocks\" & fn, _
                linktofile:=msoFalse, savewithdocument:=msoTrue, _
            Left:=Cells(j, i).Offset(1).Left, Top:=Cells(j, i).Offset(1).Top, Width:=100, Height:=100
        filename = Dir
        End If
    Next i
    Next j
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,212
Messages
6,123,656
Members
449,114
Latest member
aides

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