Hello, Friends,
I have tried to load pictures onto an image control placed in a worksheet using values to be entered into cells A1:D4 by the user.
1. Each name is assigned to one of the cells but it is not visible.
2. The user will enter one of the names and click the button .
3. The programme compares the name to the assigned name.
4. if it is correct, the corresponding picture is loaded into the image control
5. The image control is already in the worksheet.
Below is what i have tried doing but it is giving me errors
Sub LoadButton_Click()
Dim ws As Worksheet
Set ws = ActiveSheet
Dim rng As Range, r As Range
Dim Image1 As Image
Dim imgeName() As Variant
Dim s As String
Dim i As Integer, j As Integer
For i = 1 To UBound(imgeName, 1)
For j = 1 To UBound(imgeName, 2)
s = s & imgeName(i, j) & ","
Next j
s = Left(s, Len(s) - 1) & vbNewLine
Next i
MsgBox s
Set imgeName(i, j) = ws.Range("A1:D4").Value
Dim p As Picture
Dim filePath As String
filePath = ActiveWorkbook.Path & "\PICS\" & imgeName(i, j) & ".jpg"
'## delete old pic
For Each p In ws.Image1.Picture
If Not Intersect(p.TopLeftCell, rng) Is Nothing Then p.Delete
Next
'##
For Each r In rng
With ws.Image1.Picture = LoadPicture(filePath)
.Height = r.Height
.Width = r.Width
.Top = r.Top
.Left = r.Left
End With
Next
End Sub
This is a combination of methods I am using and one i copied from the net which i have adapted for the purpose. I do not understand part of it so i got confused.
I am a beginner.
Please do help me clean it and make it work.
Thanks for your usual cooperation.
Bookmarks