Save picture with VBA

tbiscardi

New Member
Joined
Mar 22, 2015
Messages
2
I am using the code below to insert a picture to a specific area within the spreadsheet. Works great, but it is linked to the file on my computer. I would like to be able to save the picture in the spreadsheet and email it for others to view.

Sub ChangeImage()
ActiveSheet.Unprotect Password:=""
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.ButtonName = "Submit"
.Title = "Select an image file"
.Filters.Clear
.Filters.Add "JPG", "*.JPG"
.Filters.Add "JPEG File Interchange Format", "*.JPEG"
.Filters.Add "Graphics Interchange Format", "*.GIF"
.Filters.Add "Portable Network Graphics", "*.PNG"
.Filters.Add "Tag Image File Format", "*.TIFF"
.Filters.Add "All Pictures", "*.*"
If .Show = -1 Then
Dim img As Object
Set img = ActiveSheet.Pictures.Insert(.SelectedItems(1))
'Scale image size
'img.ShapeRange.ScaleWidth 0.75, msoFalse, msoScaleFromTopLeft
'img.ShapeRange.ScaleHeight 0.75, msoFalse, msoScaleFromTopLeft
'Position Image
img.Left = 590
img.Top = 50
'Set image sizes in points (72 point per inch)
img.Width = 250
img.Height = 250
Else
MsgBox ("Cancelled.")
End If
End With
ActiveSheet.Protect Password:=""
End Sub
 
Hi
Try with such method of a shape collection
Code:
Set img = ActiveSheet.Shapes.AddPicture(.SelectedItems(1), msoFalse, msoTrue, ActiveCell.Left, ActiveCell.Top, -1, -1)
Regards,
 
Upvote 0

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