How to insert and resize a picture based on a cell reference

Geerod

New Member
Joined
Aug 11, 2011
Messages
8
I have been trying to get a picture to upload from a directory (listed in cell E8) and to resize itself to fit into a merged cell I made (cell J10... which takes up J10:R20). I want this to check the directory and if it has changed, re-upload the new image in the directory listed in that cell.

I came up with this macro which worked for a while...




Sub Pic1()

Dim Loc As String

Loc = Range("E8").Text

ActiveSheet.Pictures.Insert (Loc)

With ActiveSheet.Shapes(ActiveSheet.Shapes.Count)
.LockAspectRatio = False
.Top = Range("J10:R20").Top
.Left = Range("J10:R20").Left
.Height = Range("J10:R20").Height
.Width = Range("J10:R20").Width
End With
End Sub


Sub Reload()

Dim pic As Picture

For Each pic In ActiveSheet.Pictures
If pic.Name <> "Picture 1" Then
pic.Delete
End If
Next pic

Pic1
Pic2
Pic3
Pic4

End Sub



But when I changed the directory to a new directory, it stopped working with 400 error flashing up every time I run it.

Any ideas?

Thanks in Advance.
 
Last edited:

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,224,600
Messages
6,179,834
Members
452,947
Latest member
Gerry_F

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