Index/match by filenames in jpeg

gledister

Board Regular
Joined
Mar 21, 2011
Messages
173
Example: in column A we have:

richard
fred
marc
genevieve
tom

and in one folder of our HDD we have 5 jpeg named richard.jpg, fred.jpg, marc.jpg, genevieve.jpg, tom.jpg.

What we need to do is to put the pictures near the names properly.

Can that be managed by excel?

Thanks in advance.

Regards.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Assuming that the names in Column A start at Row 2, try...

Code:
[font=Verdana][color=darkblue]Option[/color] [color=darkblue]Explicit[/color]

[color=darkblue]Sub[/color] InsertImages()

    [color=darkblue]Dim[/color] strPath [color=darkblue]As[/color] [color=darkblue]String[/color]
    [color=darkblue]Dim[/color] strFile [color=darkblue]As[/color] [color=darkblue]String[/color]
    [color=darkblue]Dim[/color] LastRow [color=darkblue]As[/color] [color=darkblue]Long[/color]
    [color=darkblue]Dim[/color] i [color=darkblue]As[/color] [color=darkblue]Long[/color]
    [color=darkblue]Dim[/color] Pic [color=darkblue]As[/color] Picture
    
    Application.ScreenUpdating = [color=darkblue]False[/color]
    
    strPath = "C:\Users\Domenic\Documents\Test\"  [color=green]'change the path accordingly[/color]
    
    [color=darkblue]If[/color] Right(strPath, 1) <> "\" [color=darkblue]Then[/color] strPath = strPath & "\"
    
    LastRow = Cells(Rows.Count, "A").End(xlUp).Row
    
    [color=darkblue]For[/color] i = 2 [color=darkblue]To[/color] LastRow
        strFile = Cells(i, "A").Value & ".jpg"
        [color=darkblue]If[/color] Dir(strPath & strFile) <> "" [color=darkblue]Then[/color]
            [color=darkblue]Set[/color] Pic = ActiveSheet.Pictures.Insert(strPath & strFile)
            [color=darkblue]With[/color] Pic
                .Left = Cells(i, "B").Left
                .Top = Cells(i, "B").Top
                .Height = Cells(i, "B").Height
            [color=darkblue]End[/color] [color=darkblue]With[/color]
        [color=darkblue]Else[/color]
            Cells(i, "B").Value = "N/A"
        [color=darkblue]End[/color] [color=darkblue]If[/color]
    [color=darkblue]Next[/color] i
    
    Application.ScreenUpdating = [color=darkblue]True[/color]
        
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
[/font]
 
Upvote 0
What if the pictures are deposited online? can I replace it with an http:/etc? Will that work the same?

Thank you in advance.

Kind regards.
 
Upvote 0
Try replacing...

Code:
[font=Verdana]    strPath = "C:\Users\Domenic\Desktop\New Folder\"
    
    [color=darkblue]If[/color] Right(strPath, 1) <> "\" [color=darkblue]Then[/color] strPath = strPath & "\"
    [/font]

with

Code:
[font=Verdana]    strPath = "http://www.myexample.com/images/"
    
    [color=darkblue]If[/color] Right(strPath, 1) <> "/" [color=darkblue]Then[/color] strPath = strPath & "/"
    [/font]
 
Upvote 0
Hi Domenic,

Am turning back in this post because I want to ask an additive question about this thread.

Imagine we wanna index/match by filenames in jpeg pictures that are online but that stands in different folder....for example:

http://www.mrexcel.com/forum/images

http://www.mrexcel.com/forum/images/images2
http://www.mrexcel.com/forum/images/images2/images3
http://www.mrexcel.com/forum/thankyou
http://www.mrexcel.com/forum/thankyou/verymuch

etc.

But what they all have in common is http://www.mrexcel.com/forum/ .

Is there a way to resolve this specific problem?

Thank you in advance.

Kind regards.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,729
Members
452,939
Latest member
WCrawford

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