Insert picture

fireslguk

Active Member
Joined
Nov 11, 2005
Messages
305
How do I enable a button shape to click and insert picture just to load dialog as sometimes different pictures will be selected
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Try assigning the following macro to your button shape...

VBA Code:
Option Explicit

Sub Insert_Picture()

    'prompt user to select picture
    Dim pictureFilename As Variant
    pictureFilename = Application.GetOpenFilename( _
        FileFilter:="Image Files (*.gif;*.jpg;*.png), *.gif;*.jpg;*.png", _
        Title:="Insert Picture", _
        ButtonText:="Insert")
       
    'if user cancels, exit sub
    If pictureFilename = False Then Exit Sub
   
    'insert and position picture at active cell
    ActiveSheet.Shapes.AddPicture _
        Filename:=pictureFilename, _
        linktofile:=msoFalse, _
        savewithdocument:=msoTrue, _
        Left:=ActiveCell.Left, _
        Top:=ActiveCell.Top, _
        Width:=-1, _
        Height:=-1
   
End Sub

You can add and/or change the image file types as desired.

Hope this helps!
 
Upvote 0
Fantastic ! Thankyou - I note within the code a width and height script, what does this function do ? As I would like to set a specific size of the picture
 
Upvote 0
With -1 as their value, the width and height default to their original picture size. Simply replace -1 with the desired width and height.
 
Upvote 0
You're very welcome, and Happy New Year to you too!

Cheers!
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,623
Latest member
Techenthusiast

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