Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Load a pic into ActiveX Image control

This is a discussion on Load a pic into ActiveX Image control within the Excel Questions forums, part of the Question Forums category; Hello, I have inserted an Image ActiveX control on my sheet. I can load jpgs in it by choosing Properties ...

  1. #1
    Board Regular MartinK's Avatar
    Join Date
    Oct 2003
    Location
    Prague, CZ / Zagreb, HR
    Posts
    384

    Default Load a pic into ActiveX Image control

    Hello,

    I have inserted an Image ActiveX control on my sheet. I can load jpgs in it by choosing Properties - Picture.

    I cannot find a way how to load the picture based on a value in a different cell, e.g. A1 = Test1, load Test1.jpg, etc. The Intellisense and AuroList members is betraying me, as usual.

    BTW, does anbody have a good link about how the Autolisting help when writting the code helps? Sometimes I write a period (dot) and the members are listed. Sometimes not (like in this case).

    Thank you
    Martin

  2. #2
    Board Regular
    Join Date
    Jan 2004
    Location
    Silesia
    Posts
    98

    Default Re: Load a pic into ActiveX Image control

    You can try this code:
    Code:
    Private Sub Image1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
        Image1.Picture = LoadPicture(Application.GetOpenFilename)
    End Sub
    It opens an openfile dialog when you doubleclick the image1.
    You can change Application.GetOpenFilename to Range("A1").Value if it contains full path including filename

    Pomůže to?

  3. #3
    Board Regular MartinK's Avatar
    Join Date
    Oct 2003
    Location
    Prague, CZ / Zagreb, HR
    Posts
    384

    Default Re: Load a pic into ActiveX Image control

    Thanks! Works a treat!
    I just tweaked it to:
    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Not Intersect(Target, [a1]) Is Nothing Then
            Image1.Picture = LoadPicture([a1].Value)
        End If
    End Sub
    Martin

    Dík

  4. #4
    Board Regular
    Join Date
    Jun 2002
    Location
    Perth, Australia
    Posts
    1,416

    Default Re: Load a pic into ActiveX Image control

    Martin,

    Here’s another idea.

    Your list of JPEG descriptions in A2:A10, without the file extension.

    Image ActiveX control – Properties:
    BackColor: White
    BorderStyle: None
    PictureAlignment: Center
    PictureSizeMode: fmPictureSizeModeZoom

    Macro:
    Code:
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim WS As Worksheet
    Dim mPath As String
    If Not Application.Intersect(Range("A2:A10"), Target) Is Nothing Then
        mPath = "C:\Documents and Settings\My Pictures\" & Target.Text & ".jpg"
        If Dir(mPath) <> "" Then
            Set WS = ActiveSheet
            WS.OLEObjects("Image1").Object.Picture = LoadPicture(mPath)
        End If
    End If
    End Sub
    Single click an image description in the List.

    Regards,

    Mike

  5. #5
    Board Regular MartinK's Avatar
    Join Date
    Oct 2003
    Location
    Prague, CZ / Zagreb, HR
    Posts
    384

    Default Re: Load a pic into ActiveX Image control

    Brilliant! Thank you!
    Why this:
    Code:
    If Dir(mPath) <> "" Then
    ?
    To handle the error if no file in the folder?
    Martin

  6. #6
    Board Regular MartinK's Avatar
    Join Date
    Oct 2003
    Location
    Prague, CZ / Zagreb, HR
    Posts
    384

    Default

    OK, now this is a silly one...
    I do not want to save the pic together with the sheet.
    How to I "clear" the Image control?
    Thanks
    Martin
    Martin

    MS Excel MVP

  7. #7
    MrExcel MVP Ivan F Moala's Avatar
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    4,209

    Default Re: Load a pic into ActiveX Image control

    Code:
    Image1.Picture = LoadPicture("")
    Kind Regards,
    Ivan F Moala From the City of Sails

  8. #8
    Board Regular
    Join Date
    Jun 2002
    Location
    Perth, Australia
    Posts
    1,416

    Default Re: Load a pic into ActiveX Image control

    Ivan,

    Could not get that to work. Errors out with “Object required”. This works:
    Code:
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Dim WS As Worksheet
    Set WS = Sheets(1)
    
    With WS
       .OLEObjects("Image1").Object.Picture = LoadPicture("")
    End With
    
    End Sub
    Regards,

    Mike

  9. #9
    MrExcel MVP Ivan F Moala's Avatar
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    4,209

    Default

    Hi Mike, it worked for me ??

    Are you sure the Image is In Sheets(1) ??
    Kind Regards,
    Ivan F Moala From the City of Sails

  10. #10
    New Member Anigito's Avatar
    Join Date
    Jul 2011
    Posts
    4

    Question Re: Load a pic into ActiveX Image control

    Quote Originally Posted by Ekim View Post
    Martin,

    Here’s another idea.

    Your list of JPEG descriptions in A2:A10, without the file extension.

    Image ActiveX control – Properties:
    BackColor: White
    BorderStyle: None
    PictureAlignment: Center
    PictureSizeMode: fmPictureSizeModeZoom

    Macro:
    Code:
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim WS As Worksheet
    Dim mPath As String
    If Not Application.Intersect(Range("A2:A10"), Target) Is Nothing Then
        mPath = "C:\Documents and Settings\My Pictures\" & Target.Text & ".jpg"
        If Dir(mPath) <> "" Then
            Set WS = ActiveSheet
            WS.OLEObjects("Image1").Object.Picture = LoadPicture(mPath)
        End If
    End If
    End Sub
    Single click an image description in the List.

    Regards,

    Mike
    Thank you for sharing the knowledge.

    I have a question, if I have a list of image URLs which is concatenated from the data of the Excel Table, can I do the same, please?

    The alteration to "mPath = "C:\D ... " string is required, I guess. Will you be so kind as to help me with this?

Page 1 of 2 12 LastLast

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


DMCA.com