Error on inserting picture on active cell
Results 1 to 4 of 4

Thread: Error on inserting picture on active cell
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Dec 2010
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Error on inserting picture on active cell

    I get error 1004 on this
    Unable to get the insert property of the Pictures class

    i searched all forums to get a solution butno luck
    funny thing is it worked well and sudenly it doesn't work anymore

    Code:
    Sub AddPicture()
        Dim img As Object
        Dim Path As String
    
    Path = ("C:\Users\Pictures\piture.png")
    If Path <> "False" Then
     Set img = ActiveSheet.Pictures.Insert(Path)
    
    
                With img
                        img.Width = 10
                        img.Height = 10
                        img.Top = .Top - 2
                        img.Left = .Left - 2
                        img.Placement = xlMoveAndSize
                    End With
                    Else
                    Exit Sub
                    End If
    End Sub

  2. #2
    MrExcel MVP
    Join Date
    Mar 2004
    Location
    Canada
    Posts
    18,830
    Post Thanks / Like
    Mentioned
    35 Post(s)
    Tagged
    5 Thread(s)

    Default Re: Error on inserting picture on active cell

    It looks like you're missing the username in the path to your image...

    Code:
    Path = "C:\Users\UserName\Pictures\picture.png"
    Also, to check whether a file exists, you can use the Len and Dir functions...

    Code:
    If Len(Dir(Path, vbNormal)) = 0 Then Exit Sub
    Therefore, your code can be amended as follows...

    Code:
    Sub AddPicture()
    
        Dim img As Picture
        Dim Path As String
        
        Path = "C:\Users\UserName\Pictures\picture.png"
        
        If Len(Dir(Path, vbNormal)) = 0 Then Exit Sub
        
        Set img = ActiveSheet.Pictures.Insert(Path)
        
        With img
                .Width = 10
                .Height = 10
                .Top = .Top - 2
                .Left = .Left - 2
                .Placement = xlMoveAndSize
        End With
        
    End Sub
    Hope this helps!

  3. #3
    New Member
    Join Date
    Dec 2010
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Error on inserting picture on active cell

    I've changed it to the code above but still have the same error

    Code:
     Set img = ActiveSheet.Pictures.Insert(Path)
    this is the line highlighted as the fault

  4. #4
    New Member
    Join Date
    Dec 2010
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Error on inserting picture on active cell

    Quote Originally Posted by promoboy View Post
    I've changed it to the code above but still have the same error

    Code:
     Set img = ActiveSheet.Pictures.Insert(Path)
    this is the line highlighted as the fault
    Found the solution

    the page was protected

Some videos you may like

User Tag List

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
  •