1

I'm trying to get some pictures into an Excel sheet using the following:

Sub Addpicture()
   Dim strPath
   Dim p As Object
   strPath = <String containing path here>
   Set p = ActiveSheet.Shapes.Addpicture(strPath, msoCTrue, msoTrue, 1000, 10, 86, 129)
   ActiveSheet.Pictures.Insert (strPath)
End Sub

Both Pictures.Insert and Shapes.Addpicture just give me a rectangle in the right place containing the words "The linked image cannot be displayed. The file may have been moved, renamed, or deleted. Verify that the link points to the correct file and location"

I'm fairly sure my file path is correct. Does anyone have any insight into the issue?

Joe
  • 11
  • 1
  • 2
  • If [this post using a different method to add pictures](http://stackoverflow.com/questions/12936646/how-to-insert-a-picture-into-excel-at-a-specified-cell-position-with-vba) doesn't work and you're sure your file name matches the `Location:` under the pictures properties window + the pictures name, the next thing to ask is, is this a permissions issue? – Tyeler Sep 15 '16 at 01:30
  • Permissions might well be a good thing for me to look into. I'll try and do that now. Thanks. – Joe Sep 15 '16 at 02:57
  • The linked post gives me an "Object required" error, not sure what this means. – Joe Sep 15 '16 at 03:02

1 Answers1

0

The code works fine for me and inserts the picture twice. The first time distorted (from the Shapes.Addpicture), the second time in its original size.

Here is an example of the code with a valid path.

Sub Addpicture()
   Dim strPath
   Dim p As Object
   strPath = "D:\folder\subfolder\image.jpg"
   Set p = ActiveSheet.Shapes.Addpicture(strPath, msoCTrue, msoTrue, 1000, 10, 86, 129)
   ActiveSheet.Pictures.Insert (strPath)
End Sub

You may want to double check your path and confirm that you can access the file.

teylyn
  • 34,374
  • 4
  • 53
  • 73
  • @Joe Oh to add to this, you may also want to make sure your file path is in quotes, not <>. Not sure if the <> was just a place holder or not. – Tyeler Sep 15 '16 at 01:32
  • Cheers Tyeler, it's helpful to know that it is working for you. The <> were just placeholders and am using quotes in the actual code. I am using a Mac though, so have a slightly different path structure. Is it possible this is part of the problem? – Joe Sep 15 '16 at 02:56
  • What does your path look like in principle? Replace real folder names with "Folder" or "Subfolder" etc. – teylyn Sep 15 '16 at 05:01