How to insert an image of your choice with a macro

JamesStag

New Member
Joined
Jul 25, 2018
Messages
18
Hello everyone, i am looking to click a button and have a specific folder open to insert a picture or two. Any help would be great.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
You'll likely need to modify the following macro depending on your actual requirements. But the following macro will prompt the user to select one or more image files from the specified folder, and then insert them on the active worksheet, and located at the active cell...

Code:
Option Explicit

Sub InsertPictures()

    Dim i As Long
    
    With Application.FileDialog(msoFileDialogFilePicker)
        .AllowMultiSelect = True
        .ButtonName = "Insert"
        .Filters.Clear
        .Filters.Add Description:="Image Files", Extensions:="*.gif;*.jpg;*.png" 'add other image files as desired
        .InitialFileName = "C:\Users\Domenic\Pictures\" 'change the source folder as desired
        .Title = "Insert Picture"
        .Show
        If .SelectedItems.Count = 0 Then Exit Sub
        For i = 1 To .SelectedItems.Count
            ActiveSheet.Shapes.AddPicture Filename:=.SelectedItems(i), LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=ActiveCell.Left, Top:=ActiveCell.Top, Width:=-1, Height:=-1
        Next i
    End With
    
End Sub

Hope this helps!
 
Upvote 0
One other thing, would be, to set the location and size, any thought ? i am looking online now but any more help would be amazing.
 
Upvote 0
thank you so much.

You're very welcome, glad I could help!

One other thing, would be, to set the location and size, any thought ?

Sure, where do you want the picture or pictures inserted? And how do you want the picture or pictures sized?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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