Picture file embedded into Excel - how to retrieve with VBA

ddotson

Board Regular
Joined
Nov 9, 2004
Messages
57
Good afternoon!

I am working on an Excel template, which is going to be provided to a large group that is being asked to take pictures of properties, attach them to a spreadsheet, and send them back. I am using the following code to get the pictures (there are 5), and paste them in the correct area of the page - based on size, not a cell reference. How can I write code to have these pictures retrieved and pasted into an "upload" table to that will be uploaded to the database? Do I need to reference a cell when pasting the pictures, and then reference that same cell when grabbing them? Not sure where to go from here - any help would be appreciated!

Sub ChangeImage1()
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 = 0
img.Top = 1780

'Set image sizes in points (72 point per inch)
img.Width = 650
img.Height = 465
Else
MsgBox ("Cancelled.")
End If
End With
End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi,

This will cycle round all the pictures for you and print the names in the Immediate Window:
Code:
Sub getPics()

    Dim i As Long
    Dim j As Long

    For i = 1 To Worksheets.Count
        With Worksheets(i)
            For j = 1 To .Pictures.Count
                Debug.Print .Pictures(j).Name
            Next
        End With
    Next

End Sub

If, for instance, you wanted to copy a picture you could use:
Code:
.Pictures(j).Copy
inside the loop
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

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