Hi,
I have cobbled together the following code which works. The problem I have is that I need the file search to extend to the subfolders within the selected folder. Can anyone help?
Function picInsert(folder As String, articleCode As String, material As String, colour As String, row As Integer, column As Integer)
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim i As Integer
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Enter the folder where the images are stored
Set objFolder = objFSO.GetFolder(folder)
i = 1
For Each objFile In objFolder.Files
If objFile.Name Like (LCase(articleCode) & "*" & LCase(material) & "*" & LCase(colour) & "*") Or objFile.Name Like (UCase(articleCode) & "*" & UCase(material) & "*" & UCase(colour) & "*") Then
With ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 100, 100, 200, 50)
.Fill.UserPicture objFile
.Left = ActiveSheet.Cells(row, column).Left
.Top = ActiveSheet.Cells(row, column).Top
.Height = ActiveSheet.Cells(row, column).Height
.Width = ActiveSheet.Cells(row, column).Width
End With
End If
i = i + 1
Next objFile
End Function
I have cobbled together the following code which works. The problem I have is that I need the file search to extend to the subfolders within the selected folder. Can anyone help?
Function picInsert(folder As String, articleCode As String, material As String, colour As String, row As Integer, column As Integer)
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim i As Integer
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Enter the folder where the images are stored
Set objFolder = objFSO.GetFolder(folder)
i = 1
For Each objFile In objFolder.Files
If objFile.Name Like (LCase(articleCode) & "*" & LCase(material) & "*" & LCase(colour) & "*") Or objFile.Name Like (UCase(articleCode) & "*" & UCase(material) & "*" & UCase(colour) & "*") Then
With ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 100, 100, 200, 50)
.Fill.UserPicture objFile
.Left = ActiveSheet.Cells(row, column).Left
.Top = ActiveSheet.Cells(row, column).Top
.Height = ActiveSheet.Cells(row, column).Height
.Width = ActiveSheet.Cells(row, column).Width
End With
End If
i = i + 1
Next objFile
End Function