VBA & Macro Problems

Insert an Image into an Excel Cell from a File Path Using VBA

John WilsonJohn Wilson Nov 18, 2026 869 views

Question details

Insert an image from a file path stored on one worksheet and size it to a cell on another worksheet.

Insert an Image into an Excel Cell from a File Path Using VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA editor

In Excel, open the workbook and select Developer > Visual Basic. If the Developer tab is hidden, enable it in Excel's ribbon settings.

2
Add the macro

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

3
Run the macro

Return to Excel, select Developer > Macros, choose InsertImageFromPath, and select Run. Enable macros only if you trust the workbook.

4
Check the result

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.

Use Shapes.AddPicture to fit an image to a cell
Check sheet names and repeated runs: The code uses worksheet tab names Sheet1 and Sheet2; change them in the macro if your tabs have different names. Each run adds another picture, so delete an existing one before rerunning if you do not want duplicates.
Free Microsoft Office alternative

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.

Insert and position pictures in spreadsheets through the familiar ribbon interfaceOpen and edit Microsoft Excel formats, including XLSXUse a free, lightweight office suite with a familiar interfaceMove existing spreadsheet work to WPS Office without starting from scratch
microsoft office alternative - wps office

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.