Share via

What VBA script will help with inserting a jpeg image column C, in the same row as the file name in column A?

Anonymous
2022-12-15T02:28:58+00:00

I have a VBA script that input the file name from a folder of images in column A. My next task is to insert the image in column C such that I have:

A B C
Image file name 1 Description 1 (Not from VBA) Image 1 (100px x 100px)

Image file name 2 Description 2 (Not from VBA) Image 2 (100px x 100px)

Image file name 3 Description 3 (Not from VBA) Image 3 (100px x 100px)

Image file name 4 Description 4 (Not from VBA) Image 4 (100px x 100px)

Image file name 5 Description 5 (Not from VBA) Image 5 (100px x 100px)

.....
Image file name n Description n (Not from VBA) Image n (100px x 100px)

Current code to complete column A:

Option Explicit

Sub LoopThroughFiles()

Dim oFSO As Object

Dim oFolder As Object

Dim oFile As Object

Dim i As Integer

i = 1

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set oFolder = oFSO.GetFolder("C:\FILE PATH")

For Each oFile In oFolder.Files

Worksheets("Sheet1").Range("A" & i).Value() = oFile.Name 

i = i + 1

Next oFile

End Sub

Please help with code to add images to column c.

Microsoft 365 and Office | Excel | Other | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. HansV 462.6K Reputation points
    2022-12-15T08:49:40+00:00

    Below the line

    Worksheets("Sheet1").Range("A" & i).Value() = oFile.Name
    

    Insert

    Worksheets("Sheet1").Shapes.AddPicture oFile.Name, False, True, Workheets("Sheet1").Range("C1").Left, Workheets("Sheet1").Range("C1").Top, 100, 100
    

    Was this answer helpful?

    0 comments No comments