Last active
February 24, 2021 03:01
-
-
Save glw/809a61cd8612fb47011265b2e88a24ee to your computer and use it in GitHub Desktop.
handy image insert into excel column by file path in separate column
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. Open excel file | |
# 2. Make sure there is a column of file paths to files. Eg. C://directory1/direcotry1/image01.jpg | |
# 3. Make sure the column to the right of the file paths is open for the images to be inserted. | |
# 4. Go to Developer > Visual Basic. A new window will open. In the right hand menu under "Microsoft Excel Objects", right click the | |
# sheet name you are working with (eg. "Sheet1"). Right click it > Insert > Module. | |
# 5. A New window will pop up for your code. Copy and past the code below into the window and Run. | |
# 6. It will prompt you to select the entire column and rows containing the file path to the images. Select it and click ok. | |
Sub InsertPicFromFile() | |
Dim xRg As Range | |
Dim xCell As Range | |
Dim xVal As String | |
On Error Resume Next | |
Set xRg = Application.InputBox("Please select file path cells:", "KuTools for Excel", Selection.Address, , , , , 8) | |
If xRg Is Nothing Then Exit Sub | |
Application.ScreenUpdating = False | |
For Each xCell In xRg | |
xVal = xCell.Value | |
If xVal <> "" Then | |
ActiveSheet.Shapes.AddPicture xCell.Value, msoFalse, msoTrue, _ | |
xCell.Offset(0, 1).Left, xCell.Top, xCell.Height, _ | |
xCell.Height | |
End If | |
Next | |
Application.ScreenUpdating = True | |
End Sub | |
# source: https://www.extendoffice.com/documents/excel/5046-excel-display-image-from-file-path.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment