Insert image without link

Hatye

Board Regular
Joined
Jan 11, 2010
Messages
143
Hi,

I use the following code which works as wanted:

Code:
Private Sub CommandButton1_Click()


Dim myPicture
Dim MyObj As Object


Application.ScreenUpdating = False


Sheets("Kumkort").Unprotect


myPicture = Application.GetOpenFilename _
("Bilder (*.gif; *.jpg; *.jpeg; *.png; *.bmp; *.tif),*.gif; *.jpg; *.jpeg; *.png; *.bmp; *.tif", _
, "Velg bilde som skal settes inn")


If VarType(myPicture) = vbBoolean Then Exit Sub


    On Error Resume Next
    Sheets("Kumkort").Shapes("Kumkort_bilde1").Delete
    On Error GoTo 0
    
    On Error Resume Next
    Sheets("Kumkort").Shapes("Kumkort_bilde2").Delete
    On Error GoTo 0
    
    On Error Resume Next
    Sheets("Kumkort").Shapes("Kumkort_bilde3").Delete
    On Error GoTo 0
    
    On Error Resume Next
    Sheets("Kumkort").Shapes("Kumkort_bilde4").Delete
    On Error GoTo 0


Range("B23").Select


Set MyObj = Sheets("Kumkort").Pictures.Insert(myPicture)


    With MyObj
        With .ShapeRange
        .LockAspectRatio = msoTrue
        .Height = 328
        '.Width = 434
        .Top = Range("B23").Top
        .Left = Range("B23").Left
        .Name = "Kumkort_bilde1"
        End With
    .Placement = xlMoveAndSize
    End With
    
Set MyObj = Nothing


    ActiveSheet.Shapes.Range(Array("Kumkort_bilde1")).Select
    Selection.ShapeRange.IncrementTop 5
    Selection.ShapeRange.IncrementLeft 5


Sheets("Kumkort").Protect


Application.ScreenUpdating = True


Kumkort_BildeForm.Hide


End Sub

The only thing is that I would like the code to insert the image without link to the image file. That is; the Excel workbook should be possible to send to different users, and the image file path could be changed..

I have found something like
Code:
ActiveSheet.Shapes.AddPicture

But it doesn't work when I replace the existing code with this..
 
I can't see anything wrong with the code offhand. Where are the pictures ending up exactly?
 
Upvote 0

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Image1 is inserted correctly
Image2 is inserted in cell M23 (instead of S23)
Image3 is inserted in cell B30 (instead of B35)
Image4 is inserted in cell M30 (instead of S35)

166jinn.jpg
 
Last edited:
Upvote 0
Can you try stepping through the code just to check if the images are misplaced as soon as they are inserted, or whether they get moved?
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,326
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