macro to load a picture

Here is the macro that I use :

Option Explicit
Sub Insert_Pic()
Dim filename As String
Dim picpath As String
picpath = "D:\Images\"
Range("A1").Select
filename = ActiveCell.Value
ActiveCell.Offset(0, 1).Select
On Error Resume Next
ActiveSheet.Pictures.Insert(picpath + filename + ".jpg").Select
Selection.ShapeRange.LockAspectRatio = msoFalse
Selection.ShapeRange.Height = 100
Selection.ShapeRange.Width = 134
Selection.Cut
ActiveSheet.Paste
ActiveCell.RowHeight = 100
ActiveCell.ColumnWidth = 25
End Sub

here is the link for the pictures (2 pictures) :

2013-07-10 28 photo, picture, image on Use.com


check the highlighted is missing
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
TRY BELOW CODE

Code:
Option Explicit
Sub INSERT_PICTURES()
Dim i As Integer
Dim path As String
Dim mypath As String
path = "D:\Images\"
For i = 2 To Range("A" & Rows.Count).End(xlUp).Row
    mypath = path + Cells(i, 1) + ".jpg"
    If Dir(mypath, vbDirectory) <> "" Then
        Rows(i).RowHeight = 100
        Columns(2).ColumnWidth = 25
        Cells(i, 2).Select
        ActiveSheet.Pictures.Insert(path + Cells(i, 1) + ".jpg").Select
        Selection.ShapeRange.LockAspectRatio = msoFalse
        Selection.ShapeRange.Height = 99
        Selection.ShapeRange.Width = 134
        Selection.Cut
        ActiveSheet.Paste
     End If
Next
Cells(1, 1).Select
End Sub
 
Upvote 0
try below code

Code:
option explicit
sub insert_pictures()
dim i as integer
dim path as string
dim mypath as string
path = "d:\images\"
for i = 2 to range("a" & rows.count).end(xlup).row
    mypath = path + cells(i, 1) + ".jpg"
    if dir(mypath, vbdirectory) <> "" then
        rows(i).rowheight = 100
        columns(2).columnwidth = 25
        cells(i, 2).select
        activesheet.pictures.insert(path + cells(i, 1) + ".jpg").select
        selection.shaperange.lockaspectratio = msofalse
        selection.shaperange.height = 99
        selection.shaperange.width = 134
        selection.cut
        activesheet.paste
     end if
next
cells(1, 1).select
end sub

thankx alot kevra it's working perfectly good jobs for you
 
Upvote 0

Forum statistics

Threads
1,223,104
Messages
6,170,125
Members
452,303
Latest member
c4cstore

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