Consulting

Results 1 to 4 of 4

Thread: A text box in excel that contains a Picture taken from a file

  1. #1
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location

    A text box in excel that contains a Picture taken from a file

    How can I create a text box in excel that contains a Picture taken from a specific folder ?
    My folder is @ "C:\PeopleFolder\"
    I want to create an InputBox on a worksheet so that when I enter a name, it looks up the image name and inserts the corresponding image into a cell if it exists.
    I'll link a TextBox on the worksheet to that cell to display the image.
    How is this doable ?
    VBA or Worksheet solution; Doesn't matter.

  2. #2

    Re:: A text box in excel that contains a Picture taken from a file

    use this
    Sub Picture()Dim picname As String
        
        Range("B1").Select 'This is where picture will be inserted
    
        picname = Range("A1") 'This is the picture name
        
        On Error Resume Next
        'delete previous pic
        ActiveSheet.Pictures("ProfilePicture").Delete
        Err.Clear
        Err.Number = 0
        On Error GoTo 0
        
        If (Dir("C:\Users\JINOOB\Desktop\I A\" & picname & ".jpg") = vbNullString) Then Exit Sub
        
       ActiveSheet.Pictures.Insert("C:\Users\JINOOB\Desktop\I A\" & picname & ".jpg").Select 'Path to where pictures are stored
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''
        ' This resizes the picture
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''
        With Selection
            .Name = "ProfilePicture"
            .Left = Range("B1").Left
            .Top = Range("B1").Top
            .ShapeRange.LockAspectRatio = msoFalse
            .ShapeRange.Height = 95#
            .ShapeRange.Width = 80#
            .ShapeRange.Rotation = 0#
        End With
    End Sub
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
        If (Intersect(Target, Range("A1")) Is Nothing) Then
            Exit Sub     End If
    

  3. #3
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Something like
    Sub test()
        Dim picPath As String
        
        picPath = Application.GetOpenFilename
        If picPath = "False" Then Exit Sub
        
        ActiveSheet.Shapes("TextBox 1").Fill.UserPicture picPath
    End Sub

  4. #4
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    shah1419:

    Thanks. That code worked great.

    mikerickson :
    Another way to do it. That worked also. Thanks

    Great guys.

Posting Permissions

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