Results 1 to 10 of 11

Thread: Insert Picture in a Cell UDF

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,122
    Rep Power
    10
    Hi

    Try this version.

    Code:
    Function INSERTPICTURE(ByVal PictureFullName As String, Optional ByVal PicWidth As Single = 200, _
                                                            Optional ByVal PicHeight As Single = 150) As Boolean
            
        '// Author      : Kris @ ExcelFox.com
            
        Dim CA              As Range
        Dim picPicture
        
        Set CA = Application.Caller
        
        If Val(Application.Version) < 12 Then
            For Each picPicture In ActiveSheet.Shapes
                If picPicture.TopLeftCell.Address = CA.Address Then
                    If picPicture.Type = msoLinkedPicture Then
                        picPicture.Delete
                        Exit For
                    End If
                End If
            Next
            Set picPicture = ActiveSheet.Shapes.AddPicture(PictureFullName, 1, 0, CA.Left, CA.Top, PicWidth, PicHeight)
            GoTo Finish
        End If
        
        For Each picPicture In ActiveSheet.Pictures
            If picPicture.TopLeftCell.Address = CA.Address Then
                picPicture.Delete
                Exit For
            End If
        Next
    
        Set picPicture = ActiveSheet.Pictures.Insert(PictureFullName)
        
        With picPicture
            .Left = CA.Left + 1
            .Top = CA.Top + 1
            .Width = PicWidth
            .Height = PicHeight
        End With
        INSERTPICTURE = True
        Exit Function
    Finish:
    INSERTPICTURE = True
    End Function
    Note: It works in 2003, not sure on older versions.
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  2. #2
    Junior Member
    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Thks. How keep aspect ratio of picture.

    Quote Originally Posted by Admin View Post
    Hi

    Try this version.

    Code:
    Function INSERTPICTURE(ByVal PictureFullName As String, Optional ByVal PicWidth As Single = 200, _
                                                            Optional ByVal PicHeight As Single = 150) As Boolean
            
        '// Author      : Kris @ ExcelFox.com
            
        Dim CA              As Range
        Dim picPicture
        
        Set CA = Application.Caller
        
        If Val(Application.Version) < 12 Then
            For Each picPicture In ActiveSheet.Shapes
                If picPicture.TopLeftCell.Address = CA.Address Then
                    If picPicture.Type = msoLinkedPicture Then
                        picPicture.Delete
                        Exit For
                    End If
                End If
            Next
            Set picPicture = ActiveSheet.Shapes.AddPicture(PictureFullName, 1, 0, CA.Left, CA.Top, PicWidth, PicHeight)
            GoTo Finish
        End If
        
        For Each picPicture In ActiveSheet.Pictures
            If picPicture.TopLeftCell.Address = CA.Address Then
                picPicture.Delete
                Exit For
            End If
        Next
    
        Set picPicture = ActiveSheet.Pictures.Insert(PictureFullName)
        
        With picPicture
            .Left = CA.Left + 1
            .Top = CA.Top + 1
            .Width = PicWidth
            .Height = PicHeight
        End With
        INSERTPICTURE = True
        Exit Function
    Finish:
    INSERTPICTURE = True
    End Function
    Note: It works in 2003, not sure on older versions.
    Thanks Kris for your kind support. It work fine on 2003. But I have another question, ist possible keep aspct ratio of original picture. I read several posts in web and can't find any fine answer. Thks a lot for your support, again.

    Zapamato

Similar Threads

  1. Question on UDF LookUpConcat
    By K2` in forum Excel Help
    Replies: 4
    Last Post: 05-07-2013, 10:25 PM
  2. Trouble implementing UDF's
    By ProspectiveCounselor in forum Excel Help
    Replies: 4
    Last Post: 05-06-2013, 08:07 PM
  3. Automatically Insert Row
    By marreco in forum Excel Help
    Replies: 7
    Last Post: 12-21-2012, 06:43 PM
  4. Replies: 4
    Last Post: 05-03-2012, 10:28 AM
  5. UDF to Create In-Cell Chart in Excel
    By Admin in forum Download Center
    Replies: 0
    Last Post: 08-13-2011, 09:53 AM

Tags for this 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
  •