Insert Images as Embedded Images

mweick

New Member
Joined
Nov 9, 2012
Messages
22
Hello, I am trying to insert these images in Excel 2010 but everytime I run this Macro they get inserted as linked images. Any advice?

<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;"> Sub AddPictures()
Dim myPic As Picture
Dim wkSheet As Worksheet
Dim myRng As Range
Dim myCell As Range
Dim rowCount As Long
Dim rowCount2 As Long

Set wkSheet = Sheets(2) ' -- Change to your sheet

'-- The usual way of finding used row count for specific column
rowCount2
= wkSheet.Cells(wkSheet.Rows.Count, "C").End(xlUp).Row

If rowCount2 <> 0 Then
Set myRng = wkSheet.Range("C2", wkSheet.Cells(wkSheet.Rows.Count, "C").End(xlUp))

For Each myCell In myRng.Cells
If Trim(myCell.Value) = "" Then
MsgBox
"No file path"
ElseIf Dir(CStr(myCell.Value)) = "" Then
MsgBox myCell
.Value & " Doesn't exist!"
Else
myCell
.Offset(0, 1).Parent.Pictures.Insert (myCell.Value)

With myCell.Offset(0, 1) '1 columns to the right of C ( is D)
'-- resize image here to fit into the size of your cell
myPic
.Top = .Top
myPic
.Left = .Left
myPic
.Placement = xlMoveAndSize
End With
End If
Next myCell

Else
MsgBox
"There is no file paths in your column"
End If
End Sub</code>
 
It doesn't like the myPic.Top = .Top and myPic.Left = .left - I removed these 2 lines and...

Here is an updated look at the script and its succesfully pulling in all the images now but they layered on top of each other in the top left of the sheet and not in the respective rows...

Code:
Sub AddPictures()
 Dim myPic As Picture
 Dim wkSheet As Worksheet
 Dim myRng As Range
 Dim myCell As Range
 Dim rowCount As Long
 Dim rowCount2 As Long


     Set wkSheet = Sheet1


    rowCount2 = wkSheet.Cells(wkSheet.Rows.Count, "G").End(xlUp).Row


    If rowCount2 <> 0 Then
        Set myRng = wkSheet.Range("G2", wkSheet.Cells(wkSheet.Rows.Count, "G").End(xlUp))


        For Each myCell In myRng.Cells
               If Trim(myCell.Value) = "" Then
                    MsgBox "No file path"
               ElseIf Dir(CStr(myCell.Value)) = "" Then
                    MsgBox myCell.Value & " Doesn't exist!"
               Else
                    myCell.Offset(0, 1).Parent.Shapes.AddPicture(myCell.Value, False, True, -1, -1, -1, -1).Select
               
               With myCell.Offset(0, 1)
                    
                    End With
               
               End If
        Next myCell


    Else
        MsgBox "There is no file paths in your column"
    End If
End Sub
 
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
You're selecting after adding the image, not before.

Try selecting the destination cell first, then adding the image.
 
Upvote 0
I'm trying to understand why it didn't like the myPic.Top = .Top and myPic.Left = .Left

This is how it put the image in the proper cell and when I update the code with you suggestion it didn't like the myPic location definitions anymore.

Do I have to define it differently with this line?
 
Upvote 0
You'd need to post the code that you're using now.

Note that I'm outta' here for a few days in the morning, so hopefully someone else can pitch in.
 
Upvote 0

Forum statistics

Threads
1,214,926
Messages
6,122,305
Members
449,079
Latest member
juggernaut24

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