Macro to insert a picture and size it so it fits in cell R12

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi everyone,

I'm not very good with this so please help if you can,
I'd like a macro that can insert a picture into cell r12

no heres what i'm thinking,
when the macro is run it open the instert picture dialogue box (preferable on my pictures!)
and you choose the picture you want and click on it to insert it into excel

now I would like to move the picture so it sits where cell r12 is and sizes itself to that cell
please help if you can
thanks
Tony
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Try this:

VBA Code:
Sub InsertPicture()
  Dim sPath As String
  Dim Pict As Picture
  Dim rng As Range
  
  sPath = Environ("USERPROFILE") & "\images"
  Set rng = Range("R12")
  
  With Application.FileDialog(msoFileDialogFilePicker)
    .Title = "Select pict"
    .InitialFileName = sPath
    If .Show Then
      On Error Resume Next: ActiveSheet.Pictures("pic_tem").Delete: On Error GoTo 0
      Set Pict = ActiveSheet.Pictures.Insert(.SelectedItems.Item(1))
      With Pict
        .Name = "pic_tem"
        .ShapeRange.LockAspectRatio = msoFalse
        .Top = rng.Top
        .Left = rng.Left
        .Width = rng.Width
        .Height = rng.Height
      End With
    End If
  End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,224,827
Messages
6,181,198
Members
453,022
Latest member
RobertV1609

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