Run-Time error '-2147467259 (80004005)': Method 'InsertPictureInCell' of object 'Range' failed

PopeScooby

New Member
Joined
Aug 13, 2024
Messages
3
Office Version
  1. 365
  2. 2021
  3. 2007
Platform
  1. Windows
I need help solving the following error, "Run-Time error '-2147467259 (80004005)': Method 'InsertPictureInCell' of object 'Range' failed", and was hoping someone here could help. I have a program in Visual Studio that is opening an Excel Template, adding data, and then running some very simple VBA code in template's Module1. The VBA code is as follows...

Sub CellImage_Load(ImgCell, ImgPath)

Range(ImgCell).Select
Range(ImgCell).InsertPictureInCell (ImgPath)

End Sub

everything works fine until the line, "Range(ImgCell).InsertPictureInCell (ImgPath)", which produces the referenced error.

If I debug the error and try to run the code it will continue to error, however if I manually load one of the images and then re-test the same piece of code on a the same or a different row, it works fine. Hoping for any insight someone might be able to supply.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Just wanted to add this to my question if it helps.
It is easy to replicate this error if it helps. Just create a new workbook, add a module and the below code and replace "C:\Path To Image\Image.jpg" with a valid path to an image...

Sub CellImage_Load(ImgCell, ImgPath)

Range(ImgCell).Select
Range(ImgCell).InsertPictureInCell ImgPath

End Sub

Sub Test()

Module1.CellImage_Load "B16", "C:\Path To Image\Image.jpg"

End Sub

Try Running the Test() sub and it will error. Select any cell, then manually use from the ribbon Insert/Pictures/Place In Cell/This Device ... and select an image. After the image loads try the Test() sub again and it will work fine.
 
Upvote 0
Hi *PopeScooby. Maybe trial being specific with your code....
VBA Code:
Public Sub CellImage_Load(ImgCell As Range, ImgPath As String)
'Range(ImgCell).Select
Sheets("Sheet1").Range(ImgCell).InsertPictureInCell ImgPath
End Sub

Sub Test()
'Module1.CellImage_Load Range(B16), "C:\Path To Image\Image.jpg"
Call CellImage_Load(Range(B16), "C:\Path To Image\Image.jpg")
End Sub
HTH. Dave
 
Upvote 0
Hi *PopeScooby. Maybe trial being specific with your code....
VBA Code:
Public Sub CellImage_Load(ImgCell As Range, ImgPath As String)
'Range(ImgCell).Select
Sheets("Sheet1").Range(ImgCell).InsertPictureInCell ImgPath
End Sub

Sub Test()
'Module1.CellImage_Load Range(B16), "C:\Path To Image\Image.jpg"
Call CellImage_Load(Range(B16), "C:\Path To Image\Image.jpg")
End Sub
HTH. Dave
The InsertPictureInCell method only works if you select the cell.
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

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