VBA Insert Picture Code Not Working

Barklie

Board Regular
Joined
Jul 4, 2013
Messages
86
Hi all,

I've been through dozens of examples of how to insert a picture into an excel document using VBA and cannot get any of them to work. The one I'm currently working with that seems pretty straightforward isn't working and I can't figure out why. The second line of code is giving me an error- "Object doesn't support this property or method (Error 438)". Here is my code, if anyone knows why it's not working, please help...

Code:
Sub test()
'Add picture to excel
Range("I1").Select
Selection.Pictures.Insert ("C:\Users\barklie.estes\Desktop\timeline.jpg")

'Calgulate new picture size
With xlApp.Selection.ShapeRange
    .LockAspectRatio = msoTrue
    .Width = 10
    .Height = 8
End With
'Resize and make printable
With xlApp.Selection
    .Placement = 1 'xlMoveAndSize
    '.Placement = 2 'xlMove
    '.Placement = 3 'xlFreeFloating
    .PrintObject = True
End With
    
End Sub


Thanks!
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
This will add the picture and size it to cell I1.

Code:
Sub Insert_Picture()

    Dim PicRange As Range


    Set PicRange = Range("I1") 'Change to Set PicRange = Selection if needed


    ActiveSheet.Pictures.Insert("C:\Users\barklie.estes\Desktop\timeline.jpg").Select


    With Selection


        '.ShapeRange.LockAspectRatio = msoFalse  'Uncomment if required
        .Left = PicRange.Left
        .Top = PicRange.Top
        .Width = PicRange.Width
        .Height = PicRange.Height


    End With


End Sub


Hope this Helps
WD
 
Upvote 0
This will add the picture and size it to cell I1.

Code:
Sub Insert_Picture()

    Dim PicRange As Range


    Set PicRange = Range("I1") 'Change to Set PicRange = Selection if needed


    ActiveSheet.Pictures.Insert("C:\Users\barklie.estes\Desktop\timeline.jpg").Select


    With Selection


        '.ShapeRange.LockAspectRatio = msoFalse  'Uncomment if required
        .Left = PicRange.Left
        .Top = PicRange.Top
        .Width = PicRange.Width
        .Height = PicRange.Height


    End With


End Sub


Hope this Helps
WD

[/QOUTE=bbbsizemore]

I keep telling me to rebug below. it turns it yellow.

ActiveSheet.Pictures.insert("C:\Libraries\Pictures.jpg").Select
 
Upvote 0
This will add the picture and size it to cell I1.

Code:
Sub Insert_Picture()

    Dim PicRange As Range


    Set PicRange = Range("I1") 'Change to Set PicRange = Selection if needed


    ActiveSheet.Pictures.Insert("C:\Users\barklie.estes\Desktop\timeline.jpg").Select


    With Selection


        '.ShapeRange.LockAspectRatio = msoFalse  'Uncomment if required
        .Left = PicRange.Left
        .Top = PicRange.Top
        .Width = PicRange.Width
        .Height = PicRange.Height


    End With


End Sub


Hope this Helps
WD

[/QOUTE=bbbsizemore]

I keep telling me to debug below. it turns it yellow. It also say that it cannot get the property for insert class.

ActiveSheet.Pictures.insert("C:\Libraries\Pictures.jpg").Select
 
Upvote 0

Forum statistics

Threads
1,213,497
Messages
6,113,999
Members
448,541
Latest member
iparraguirre89

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