VBA Insert Picture Code Not Working

Barklie

Board Regular
Joined
Jul 4, 2013
Messages
76
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!
 

Some videos you may like

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

William Day

Board Regular
Joined
Jul 21, 2013
Messages
54
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
 

bbbsizemore

New Member
Joined
Dec 11, 2014
Messages
20
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
 

bbbsizemore

New Member
Joined
Dec 11, 2014
Messages
20
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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,734
Messages
5,597,809
Members
414,177
Latest member
RezaAkhund

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
Top