Insert Image from Image Control

Hmerman

Board Regular
Joined
Oct 2, 2016
Messages
102
Hello,
I have an Userform that when you click on a button named Photo it opens Windows Camera App and when your finished taking photos (you close the App). You then click on another button on the Userform that should load the mostrecentfile into a Image Control (the code is still a bit wonky on this particular aspect, but I am getting there).

Once the image is loaded in the Image Control I want to place it directly from the Image Control on a specific range on Sheet1. The thing is I am uncertain if this is possible? I have written the code and kept it simple, but I get an Error 1004: Specified value out of range. The error is in the line in red.

Code:
Dim Rng As Range
    Dim img As Picture
    dim sht as WorkSheet
      
      sht = Sheet1
      Set Rng = sht.Range("B15")
    With Rng
       
        [COLOR=#ff0000]Set img = ActiveSheet.Shapes.AddPicture(Image1.Picture, False, False, 5, 5, 1, 1)[/COLOR]
        
        With img
            .Height = 200
            .Width = 120
            .Left = Rng.Left
            .Top = Rng.Top

        End With
        
        
    End With

Is this possible?
Can someone please help me?

Regards,
 
Last edited:

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
try this:
Code:
Dim shp As Excel.Shape

SavePicture Me.Image1.Picture, Environ("Temp") & "\myTemp.jpg"

Set shp = Sheet4.Shapes.AddShape(msoShapeRectangle, Range("B15").Left, Range("B15").Top, 120, 200)

shp.Fill.UserPicture Environ("Temp") & "\myTemp.jpg"
 
Last edited:
Upvote 0
That is Excellent. Thanks.

Is it possible to name the shape dinamically every time it is added? E.g. Rect1; Rect2. So I can code a loop that looks through all the objects to see if it exists before adding another shape on another destination
Offset(a ,2)
a = a + 15 from original. I can't seem to find a name argument in the Shape.AddShape Method help files.

Sorry I know this is not what I originally asked.

Or should I rather fill Range("B15") = with "spaces" so it is not empty, and rather look for the empty cell?
 
Upvote 0
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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