Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88854

Insert Images into Excel from sub directories based on cell value

$
0
0

I am a VBA novice but have been able to modify the below code to insert images in my spreadsheet based on cell values as long as the images are in the specific folder. How would I go about changing the code so that it searches all the sub folders within the directory? Any help would be greatly appreciated.

  Public Sub Add_Pics_Example()

Dim oCell As Range
Dim oRange As Range
Dim oActive As Worksheet
Dim sPath As String
Dim sFile As String
Dim oShape As Shape

Worksheets("Range").Activate



sPath = "Z:\Pictures\Product Images\"

ActiveSheet.DrawingObjects.Select
Selection.Delete

Set oActive = ActiveSheet

Set oRange = oActive.Range("B4:bz4")

On Error Resume Next

For Each oCell In oRange


sFile = oCell.Value & ".jpg"

Set oShape = oActive.Shapes.AddPicture(sPath & sFile, False, True, _
oCell.Offset(-3, 0).Left + 30, oCell.Offset(-3, 0).Top + 3, 60, 60)



Next oCell

On Error GoTo 0

Application.ScreenUpdating = True

End Sub

Viewing all articles
Browse latest Browse all 88854


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>