Importing images into userform

MrPink1986

Active Member
Joined
May 1, 2012
Messages
252
Hi,

I have a multi page user form that I am using to predict scores for the premier league soccer fixtures each week. Within each page I have 1 fixture made up of a home team and an away team. This data changes week on week depending on the a web import. I want to add two images to each page which will represent the team crest of the team in each text box.

I have the team crests on a tab named "Pictures" with each crest in a cell beginning with C2.
My text boxes are named Fixture1_Home Fixture1_Away - Fixture10_Home Fixture10_Away this will pick up the 20 teams each week.

In my image box I want some code to say if Fixture1_Home is X then pick up the picture and apply this to the image box (my image boxes are named Fix1_Home_Image, Fix1_Away_Image etc)

Once this is defined I am then presuming I can call the Sub UserForm_Initialize stage.

I have attempted the below for the Manchester United team as the away team in the fixture 9 test box.

Code:
Private Sub Fix9_Away_Image_Click()If Fixture9_Away_Change = "Manchester United" Then
Fix9_Away_Image.Picture = Sheets("Pictures").Range("C2")
End If
End Sub

Any help is greatly appreciated.
 
Re: Help importing images into userform

Ok - I will post an alternative method tomorrow using worksheet pictures.
It might make things simpler if the logos are named to match the text rather than referring to cells. Is that ok with you?
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Re: Help importing images into userform

Absolutely - the only requirement is that they reside somewhere that can be accessible for multiple users and the naming of them is flexible.
Ok - I will post an alternative method tomorrow using worksheet pictures.
It might make things simpler if the logos are named to match the text rather than referring to cells. Is that ok with you?
 
Upvote 0
Re: Help importing images into userform

I'm not sure why that should be !!
I've just opened my original Link and also the one you posted in Quote!!!
 
Upvote 0
Re: Help importing images into userform

I could send you the code and some instructions for the userform/pictures if you would like ????
 
Upvote 0
Re: Help importing images into userform

The userform has A multipage with 10 pages
Each Page has 2 Image controls and 2 Textboxes

The pages were filled with Image controls and Textboxes in page sequence
So Page 0 has Textbox 1 & 2 and Image 1 and 2.
The userform also has a CommandButton to load the pages.


Sheet1 column "A" (starting row2) has the names of the Football clubs for the current week.
Sheet1 also Has a CommandButton to open the Userform, in sheet1 :- Userform1.show

Sheet2 has all the Logo Images for each club as required.
Each image is named in the "Name Box" with its Club "Name".

This is the Userform Module code:-

Code:
Option Explicit


Private Sub CommandButton1_Click()
'Pic_Football
Dim Ctrl As Control, n As Long, c As Control, p As Long, t As Long
Dim Rng As Range, Dn As Range
Set Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))


For n = 0 To MultiPage1.Pages.Count - 1
    For Each c In MultiPage1.Pages(n).Controls
       If TypeName(c) = "TextBox" Then
            t = t + 1
            If t <= Rng.Count And Rng(t) <> "" Then _
            c.Value = Rng(t)
        End If
        If TypeName(c) = "Image" Then
           p = p + 1
          If p <= Rng.Count And Rng(p) <> "" Then _
          Call Pict(p, Rng(p))
        End If
    Next c
Next n
End Sub






Private Sub UserForm_Initialize()
Me.MultiPage1.Value = 0
End Sub
Sub Pict(n, pic)
Dim Rng As Excel.Range
Dim cht As Excel.ChartObject
Dim Pth As String
Dim Strpath As String


Set pic = Sheets("sheet2").Shapes(pic)
pic.Copy


Strpath = ThisWorkbook.Path & "\Temp.jpg"
   Set cht = ActiveSheet.ChartObjects.Add(100, 0, pic.Width, pic.Height)
    cht.Chart.Paste
      cht.Chart.Export Strpath
        cht.Delete
Set cht = Nothing
Me.Controls("Image" & n).Picture = LoadPicture(Strpath)
End Sub

When the userform is opened and the commanbutton is clicked, each club name in column "A" is used to fill the appropriate textbox and Image (in sequence) .

The Images are loaded in the Image controls by creating a chart object that is saved to the ActiveworkBook path as a .jpg file then imported back to the appropriate image control.

I hope you can get it working ???
 
Upvote 0
Re: Help importing images into userform

@MickG,

I download your file, and I can't see that picture in userform. That place is "white".
I can see in Textbox the name of team, but no pictures.
What is wrong?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,189
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top