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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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,226,729
Messages
6,192,696
Members
453,747
Latest member
tylerhyatt04

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