Error on inserting picture on active cell

promoboy

New Member
Joined
Dec 5, 2010
Messages
19
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
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
It looks like you're missing the username in the path to your image...

Code:
Path = "C:\Users\[COLOR=#ff0000]UserName\[/COLOR]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!
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,489
Messages
6,113,953
Members
448,535
Latest member
alrossman

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top