Nsert an picture into an Excel file

Can you please show me how to insert an image into an Excel file? I searched for the method but couldn’t find the insert image at cell tool anywhere.

You can check the below thread @phuc_trinh

Regards

1 Like

@phuc_trinh

Sub InsertImage()
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Sheets("Sheet1") ' Change to your sheet name
    ws.Pictures.Insert("C:\path\to\your\image.jpg").Select ' Change to your image path
    With Selection.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

Use this invoke vba code inside the Excel scope

1 Like

After downloading, I adjusted the excel file path, but when I launched it, it reported an error as shown.

i tried it but it gives me error as shown in the picture, can you guide me to fix it?

@phuc_trinh
Enable Trust Center access
Open Excel go to File–>Options–>Trust Center–>Trust Center Settings–>Macro Settings–>Select the Trust Center access to the Vba project model checkbox.
Second one:
Please check the code if you pass all the data correctly

1 Like

Hi @phuc_trinh

Can you share the value present in the value to save field?

Regards

1 Like

Thank you very much, continue when entering excel error message.

Yes thank you, please see attached image.

@phuc_trinh
The excel sheet i Pass like this

Set ws = ThisWorkbook.Sheets("Sheet1")

But you pass

  Set Ws=Pdf to Excel.Sheets1("Sheet1")

Please change this as it was

1 Like

has the activity:
Insert Image At Cell

1 Like

Sorry to bother you but when I change the path containing the image file, I get an error as shown in the picture. The folder containing my images ( E:\UiPath\A6-2F\PDF to Excel\images ).

image

Thank you very much.

Hi @phuc_trinh

I have asked you to share the value that you are trying to assign to the imageFiles variable. Please share that screenshot.

Regards

1 Like

@phuc_trinh

Please check this step by step tutorial to get the insert image working

Cheers

1 Like

Sorry, I chose the wrong path and successfully edited it, but when I added the insert column to sheet2, it reported a Trust Access error while I had already edited it and sheet1 was successful. Can you guide me to fix the error?

@phuc_trinh

Enable Trust Center access
Open Excel go to File–>Options–>Trust Center–>Trust Center Settings–>Macro Settings–>Select the Trust Center access to the Vba project model checkbox.
The Second reason May be:
You don’t pass the data correctly or you may do some mistake in your code.So Please check once the code

1 Like

Hi @phuc_trinh

Please refer the below screenshot for better understanding:

I have asked you to give your folder path so in my case the folder path is shown as below and please give your correct folder path over there.

imageFiles = System.IO.Directory.GetFiles("C:\Users\vrdabberu\Downloads\images","*.png")

Regards

1 Like

yes that’s exactly it, i don’t know where to fill it in. The folder path contains my images (E:\UiPath\A6-2F\PDF to Excel\images)

Hi @phuc_trinh

Please use below syntax in the assign activity for your code to execute .

imageFiles = System.IO.Directory.GetFiles("E:\UiPath\A6-2F\PDF to Excel\images","*.png")

Regards

1 Like