Insert picture macro

BradM1212

New Member
Joined
Oct 31, 2002
Messages
11
I'm trying to have a macro insert a picture automatically. When I use the record macro feature and go through the steps, it doesnt do it exactly the way I want. Basically, I would like the insert picture dialog box to open, then have the user be able to select the file (picture) to be inserted. Using the record macro feature only records the mousestrokes AFTER i selected a specific picture, and records the file I selected. When activating the macro later, it asks for the picture I used when I recorded the macro initially. Hope that makes sense.
An added bonus would be for the picture to automatically re-size itself to the borders I established within the spreadsheet since some pics may be 320x200, 640x480, etc.

Thanks,
Brad
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
For the first part, it seems like you want the line of code:

Code:
Application.Dialogs(xlDialogInsertPicture).Show
 
Upvote 0
Try this

Code:
Sub Add_Picture()
'
' Macro recorded 9/7/01 by Terry Moffitt
'

'
    Application.ScreenUpdating = False

    'varible Picture1 is inserted down below - ***change both***
    Picture1 = Application.GetOpenFilename("Picture,*.JPG,Picture,*.JPEG,Picture,*.GIF,Picture,*.BMP")
    'edit "("Picture,*.*")" section to add or chanve visible file types
    
    ActiveSheet.Pictures.Insert(Picture1).Select
    Selection.ShapeRange.LockAspectRatio = msoTrue
    Selection.ShapeRange.Height = 175
    Selection.ShapeRange.Width = 234
    Application.ScreenUpdating = True

End Sub

Edit hight and width to your needs. picture will be placed in active cell.
:idea: :)
 
Upvote 0

Forum statistics

Threads
1,216,102
Messages
6,128,852
Members
449,471
Latest member
lachbee

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