Consulting

Results 1 to 3 of 3

Thread: Assign picture to Image Control

  1. #1
    VBAX Expert
    Joined
    Feb 2005
    Posts
    929
    Location

    Assign picture to Image Control

    I am running xl2K under WinXP. I wish to assign a picture file to an Image control. I can do it manually by creating the Image control (essentially a shape) and then diddling with properties to define the jpg file, picture format, etc. But when I look at the code created via the macro recorder, most of what I did is not there. Controlling the creating, location, size, etc., with VBA is pretty easy, but how do I assign the jpg file and the picture format.
    "It's not just the due date that's important, it's also the do date" [MWE]

    When your problem has been resolved, mark the thread SOLVED by clicking on the Thread Tools dropdown menu at the top of the thread.

  2. #2
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    You have to put an image control on sheet 1 with the toolbox and give this the name Person_Image. Then you put names starting from row 2 in column A. Each name has the same filename for your picture. And your pictures are stored under My pictures.[VBA]Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    'In column A we put the names of the person
    If Target.Column = 1 And Target.Row > 1 Then
    If Target.Value = vbNullString Then
    Person_Image.Picture = LoadPicture("")
    Else
    'The imagecontrol on sheet1 is named Person_Image
    With Person_Image
    'The name of the file is the same as the name on your worksheet
    'and all your pictures are stored under My pictures
    .Picture = LoadPicture("C:\Documents and Settings\USERNAME\My documents\" & _
    "My pictures\" & Target.Value & ".jpg")
    .Height = 100
    .Width = 100
    'Fit picture to the size you want
    .PictureSizeMode = fmPictureSizeModeStretch
    End With
    End If
    End If
    End Sub[/VBA]

  3. #3
    VBAX Expert
    Joined
    Feb 2005
    Posts
    929
    Location
    Thanks for your reply, but your approach is much too specific, i.e., name of ImageControl, how it is created, how it is accessed, etc. Also, no matter what I named the ImageControl, e.g., "Person_Image" or anything else, the

    [vba]With Person_Image[/vba] (or whatever I called it) line of code generated an immediate error. Part of the problem is that although the manual method appears to create a ImageControl (and I can fiddle with it manually), the macro recorder code generates a shape that has no "picture" attribute

    So let's go back to square one; I need a method to create an ImageControl via VBA. No manual steps.
    "It's not just the due date that's important, it's also the do date" [MWE]

    When your problem has been resolved, mark the thread SOLVED by clicking on the Thread Tools dropdown menu at the top of the thread.

Posting Permissions

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