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
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
After downloading, I adjusted the excel file path, but when I launched it, it reported an error as shown.
@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
@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
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 ).
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
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?
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
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
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