Hi, below is my code I use to look up products for an image. It looks in a folder for the correct photo. But we would like to now separate all the photos into sub folders, based on class.
Is there a way to modify my code to look into sub folders for the image.jpg
Private Sub Worksheet_Change(ByVal Target As Range)
Sheets("TOPn").Select
ActiveSheet.Unprotect
Rows("7:7").Select
ActiveWindow.SmallScroll Down:=462
Rows("7:499").Select
Selection.RowHeight = 100
Sheets("TOPn").Select
ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
False, AllowUsingPivotTables:=True
'Sub Products_Click()
Application.ScreenUpdating = False
Dim myObj
Dim Pictur
Set myObj = ActiveSheet.DrawingObjects
For Each Pictur In myObj
If Left(Pictur.Name, 7) = "Picture" Then
Pictur.Select
Pictur.Delete
End If
Next
Dim EmployeeName As String, T1 As String
'*****PHOTO 1
myDir = "U:\Pictures\Products"
EmployeeName = Range("D7")
T1 = ".jpg"
On Error GoTo errormessage:
ActiveSheet.Shapes.AddPicture Filename:=myDir & EmployeeName & T1, linktofile:=msoFalse, savewithdocument:=msoTrue, Left:=1105, Top:=200, width:=100, height:=100
errormessage:
If Err.Number = 1004 Then
'MsgBox "File does not exist." & vbCrLf & "Check the model! (D7)"
'Range("A2").Value = ""
'Range("B2").Value = ""
End If
'Run next photo
Call cmdDisplayPhoto_2_Click
Call cmdDisplayPhoto_3_Click
Call cmdDisplayPhoto_4_Click
Call cmdDisplayPhoto_5_Click
Call cmdDisplayPhoto_6_Click
Call cmdDisplayPhoto_7_Click
Call cmdDisplayPhoto_8_Click
Call cmdDisplayPhoto_9_Click
Call cmdDisplayPhoto_10_Click
Call cmdDisplayPhoto_11_Click
Call cmdDisplayPhoto_12_Click
Call cmdDisplayPhoto_13_Click
Call cmdDisplayPhoto_14_Click
Call cmdDisplayPhoto_15_Click
Call cmdDisplayPhoto_16_Click
Call cmdDisplayPhoto_17_Click
Call cmdDisplayPhoto_18_Click
Call cmdDisplayPhoto_19_Click
Call cmdDisplayPhoto_20_Click
Call cmdDisplayPhoto_21_Click
Call cmdDisplayPhoto_22_Click
Call cmdDisplayPhoto_23_Click
Call cmdDisplayPhoto_24_Click
Call cmdDisplayPhoto_25_Click
Call cmdDisplayPhoto_26_Click
Call cmdDisplayPhoto_27_Click
Call cmdDisplayPhoto_28_Click
Call cmdDisplayPhoto_29_Click
End Sub
Is there a way to modify my code to look into sub folders for the image.jpg
Private Sub Worksheet_Change(ByVal Target As Range)
Sheets("TOPn").Select
ActiveSheet.Unprotect
Rows("7:7").Select
ActiveWindow.SmallScroll Down:=462
Rows("7:499").Select
Selection.RowHeight = 100
Sheets("TOPn").Select
ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
False, AllowUsingPivotTables:=True
'Sub Products_Click()
Application.ScreenUpdating = False
Dim myObj
Dim Pictur
Set myObj = ActiveSheet.DrawingObjects
For Each Pictur In myObj
If Left(Pictur.Name, 7) = "Picture" Then
Pictur.Select
Pictur.Delete
End If
Next
Dim EmployeeName As String, T1 As String
'*****PHOTO 1
myDir = "U:\Pictures\Products"
EmployeeName = Range("D7")
T1 = ".jpg"
On Error GoTo errormessage:
ActiveSheet.Shapes.AddPicture Filename:=myDir & EmployeeName & T1, linktofile:=msoFalse, savewithdocument:=msoTrue, Left:=1105, Top:=200, width:=100, height:=100
errormessage:
If Err.Number = 1004 Then
'MsgBox "File does not exist." & vbCrLf & "Check the model! (D7)"
'Range("A2").Value = ""
'Range("B2").Value = ""
End If
'Run next photo
Call cmdDisplayPhoto_2_Click
Call cmdDisplayPhoto_3_Click
Call cmdDisplayPhoto_4_Click
Call cmdDisplayPhoto_5_Click
Call cmdDisplayPhoto_6_Click
Call cmdDisplayPhoto_7_Click
Call cmdDisplayPhoto_8_Click
Call cmdDisplayPhoto_9_Click
Call cmdDisplayPhoto_10_Click
Call cmdDisplayPhoto_11_Click
Call cmdDisplayPhoto_12_Click
Call cmdDisplayPhoto_13_Click
Call cmdDisplayPhoto_14_Click
Call cmdDisplayPhoto_15_Click
Call cmdDisplayPhoto_16_Click
Call cmdDisplayPhoto_17_Click
Call cmdDisplayPhoto_18_Click
Call cmdDisplayPhoto_19_Click
Call cmdDisplayPhoto_20_Click
Call cmdDisplayPhoto_21_Click
Call cmdDisplayPhoto_22_Click
Call cmdDisplayPhoto_23_Click
Call cmdDisplayPhoto_24_Click
Call cmdDisplayPhoto_25_Click
Call cmdDisplayPhoto_26_Click
Call cmdDisplayPhoto_27_Click
Call cmdDisplayPhoto_28_Click
Call cmdDisplayPhoto_29_Click
End Sub