kelly mort
Well-known Member
- Joined
- Apr 10, 2017
- Messages
- 2,169
- Office Version
- 2016
- Platform
- Windows
Hi,
This code is giving me a headache and I need someone fix it for me.
Currently both controls are loading the image from same folder "Picture1".
I want the second control to load from "picture2".
I have tried some stuffs but the script keeps laughing at me .
This code is giving me a headache and I need someone fix it for me.
Currently both controls are loading the image from same folder "Picture1".
I want the second control to load from "picture2".
I have tried some stuffs but the script keeps laughing at me .
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target = Me.[h9] Or Target = Me.[h36] Then
Select Case Target.Address
Case Is = "$H$9"
LoadIm "Image1", Me.[h9]
Case Is = "$H$36"
LoadIm "Image2", Me.[h36]
End Select
End If
End Sub
Sub LoadIm(cname$, r As Range)
Dim fpath$, sfile$
[COLOR=#ff0000][B]fpath = ThisWorkbook.Path & "\Picture1"[/B][/COLOR]
sfile = Dir(fpath & "\" & Right(r.Text, 3) & ".*")
If sfile <> vbNullString Then
Me.OLEObjects(cname).Object.Picture = LoadPicture(fpath & "\" & sfile)
Else
Me.OLEObjects(cname).Object.Picture = LoadPicture("")
End If
If Err.Number = 53 Then Me.OLEObjects(cname).Object.Picture = LoadPicture("")
End Sub