-->

Excel: Automatically Add Image Extension ".jpg" or Insert Image Path

In this tutorial, I will show you how to create a very simple yet life-saving excel macro. If you’re a Product Lister you might have experienced working on an excel sheet with thousands of images file names or image path, updating them one by one, so repetitive and time-consuming right? 

But here's the good news for you, I have found a better way to do it through Excel’s own tools for the designed to accomplish the repetitive task, the MACROS!
This macro code allows you to achieve the following task effortlessly:

*Add any image extension to any image name.
*Add additional text or pathname before the image name.
*Select and run. Easy to customize.

1. First, create a new macro, click the Excel's Developer Tab > Record.

2. Name your macro as RENAMER then, hit OK.


3. Click the MACROS menu —Microsoft Visual Basic module dialog will open


4. Between the Sub Renamer and End Sub add this line:

Dim Cell As Range
For Each Cell In Selection
If Not IsEmpty(Cell) And Right(Cell, 4) <> "..jpg" Then
Cell = "" & Replace(Trim(Cell), "", "-") & ".jpg"
End If
Next Cell

5. Press CTRL + S to save your code.

6. To run your macro, select an excel column with image file names that you want to add.JPG extension, then run your Renamer macro as shown:


Adding an Image Path

1. Just open your RENAMER macro and click the EDIT menu then add the image path inside the quote next the cell=.
Your final code will look like this:
Dim Cell As Range
For Each Cell In Selection
If Not IsEmpty(Cell) And Right(Cell, 4) <> "..jpg" Then
Cell = "www.yourdomain.com /images/" & Replace(Trim(Cell), "", "-") & ".jpg"
End If
Next Cell

Here’s the screenshot using my fictitious image path.


Beware! This macro doesn't allow you to undo the changes once you run it. So you better back up your file always before proceeding.