Nsert an picture into an Excel file

exactly i have turned on trust in excel, and i successfully inserted the image into sheet1 but when i copy another VBA to insert into another sheet2, it says to continue turning on trust.
Because i am inserting images into multiple sheets.

yes thank you i have edited the path successfully but it keeps reporting an error and can you help me how to edit the position and size of the inserted image.

Please check the Variables contains any values or not that you have assigned to that activity @phuc_trinh

Regards

@phuc_trinh

Sub InsertImage()
    Dim ws As Worksheet
    Dim wsName As String
    wsName = "Sheet1" ' Change to your desired sheet name
    Dim imagePath As String
    imagePath = "C:\Users\rlgandu\Pictures\ID Picture.png" ' Change to your image path

    On Error Resume Next
    Set ws = ThisWorkbook.Sheets(wsName)
    On Error GoTo 0
    
    ' If the sheet does not exist, create it
    If ws Is Nothing Then
        Set ws = ThisWorkbook.Sheets.Add(After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count))
        ws.Name = wsName
    End If

    ' Insert the image and format it
    Dim pic As Object
    Set pic = ws.Pictures.Insert(imagePath)
    With pic.ShapeRange
        .LockAspectRatio = msoFalse
        .Left = ws.Cells(1, 1).Left ' Change to your desired cell
        .Top = ws.Cells(1, 1).Top ' Change to your desired cell
        .Width = 100 ' Set your desired width
        .Height = 100 ' Set your desired height
    End With
End Sub

I changed the Vb code a little bit.So this work for you check this and update me

1 Like

Hi @phuc_trinh

Delete that activity it’s not necessary over there. Try to excute the code and let me know the output.

Regards

1 Like

yes thank you it is very helpful for me, and hope you can help me with the last step is if i want to insert image 2 into sheet2 and image 3 into sheet3 how to do?
And how if I want to continue inserting the 2nd image into sheet1 .

yes i was able to launch it, but my problem is how can i choose to freeze image 2 inserted in sheet2 and image 3 inserted in sheet3. please help me.

I tried it but it gives me this error can you show me how to fix it.

@phuc_trinh
InsertImage.txt (2.3 KB)
For inserting Images in different sheets use multiple invoke vba.Inserting Multiple Images in Single Sheet Use The first invoke vba code .

1 Like

yes thank you it is very helpful for me.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.