Insert an Image into an Excel Cell from a File Path Using VBA
Question details
Insert an image from a file path stored on one worksheet and size it to a cell on another worksheet.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- The IMAGE function is unavailable, and the user wants to use VBA to place an image over a target cell.
- Observed behavior
- The image should fit the target cell and move and resize with it.
Enter an accessible full image file path in Sheet1!G1 and confirm that Sheet2!K8 is the intended target. Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) and ensure macros are permitted by your organization's security settings.
Use Shapes.AddPicture to fit an image to a cell
Use this macro when the image path is in Sheet1!G1 and the target cell is Sheet2!K8.
The macro inserts a picture as a worksheet shape positioned over the cell, not as a cell value. It stretches the picture to match the cell's width and height, which may change its proportions.
In Excel, open the workbook and select Developer > Visual Basic. If the Developer tab is hidden, enable it in Excel's ribbon settings.
In the VBA editor, select Insert > Module and paste: Sub InsertImageFromPath() Dim target As Range Dim imagePath As String Dim pic As Shape imagePath = ThisWorkbook.Worksheets("Sheet1").Range("G1").Value Set target = ThisWorkbook.Worksheets("Sheet2").Range("K8") Set pic = target.Worksheet.Shapes.AddPicture( _ Filename:=imagePath, LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, _ Left:=target.Left, Top:=target.Top, Width:=target.Width, Height:=target.Height) pic.Placement = xlMoveAndSize End Sub
Return to Excel, select Developer > Macros, choose InsertImageFromPath, and select Run. Enable macros only if you trust the workbook.
Open Sheet2 and check cell K8. Adjust the cell's row height or column width if needed; the picture is set to move and resize with the cell.

Work with spreadsheet images in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for opening spreadsheets and working with images. It supports common Excel formats for an easier transition, although it does not fix Excel VBA issues and macro support can vary by edition.

Frequently Asked Questions
Does the picture become part of the Excel cell?
No. Shapes.AddPicture creates a worksheet shape positioned over the cell. Setting Placement to xlMoveAndSize makes it move and resize with the cell.
Why does the macro fail when adding the picture?
Check that Sheet1!G1 contains a valid, accessible full path to a supported image file. Also verify that the worksheet tab names in the code match those in your workbook.
How do I keep the macro in the workbook?
Use File > Save As and choose Excel Macro-Enabled Workbook (.xlsm). A standard .xlsx file cannot retain VBA macros.
Will the image be stored in the workbook?
Yes. The macro uses LinkToFile:=msoFalse and SaveWithDocument:=msoTrue to embed the image rather than link to the file.




