For a document I'm using multiple databases (in seperate worksheets) and multiple dropdown menus (combo boxes) which are populated by those databases. On change it's adding some information and a picture to the main sheet, which is retrieved from those databases. All works well, but... Once I try to change a cell in one of the databases (doesn't matter which one), it's giving me an error with the dropdown boxes:
"Run-time error '1004': Method 'OLEObjects' of object '_worksheet' failed"
(Debug highlights on the line with .OLEObjects)
What am I overseeing here? Any help is much appreciated!
Private Sub CDL1_change()
Dim c As Range, MyPath, MyFile As String, WS As Worksheet
MyPath = Sheets("TeamChart").Range("C95").Value
Set WS = ActiveSheet
With Worksheets("CDL").Range("rngCDL")
Set c = .Find(CDL1.Value, LookIn:=xlValues, lookat:=xlWhole)
If Not c Is Nothing Then
Sheets("TeamChart").Range("L5") = c.Offset(0, 0).Value
Sheets("TeamChart").Range("M6") = c.Offset(0, 1).Value
Sheets("TeamChart").Range("M7") = c.Offset(0, 2).Value
MyFile = c.Offset(0, 3).Value
With WS
.OLEObjects("picCDL").Object.Picture = LoadPicture(MyPath & MyFile)
End With
Else
Sheets("TeamChart").Range("L5") = "Not Found"
Sheets("TeamChart").Range("M6") = "Not Found"
Sheets("TeamChart").Range("M7") = "Not Found"
End If
End With
End Sub
This is cell C95's value: G:\xxx\Fotos\. I've already tried it with MyFile as being both the path and the file name, gave the same results.
(MyPath & MyFile)is not a valid path because eitherMyPathdoesn't end with a backslash orMyFiledoesn't start with one? Perhaps it should be(MyPath & "\" & MyFile)?"\"will always work (could be"/"too) ... so maybe useApplication.PathSeparatorSheets("TeamChart").Range("C95").Valueetc ...)