title: Insert (and then reference) a picture into Excel using VBA
body: <p>I'm trying to insert a picture into a worksheet using VBA, that I can later reference by name (to for example delete, or hide).  </p>
  
  <p>I can insert the image using code similar to the below:</p>
  
  <pre><code> ActiveSheet.Shapes.AddPicture Filename:="image.jpg", linktofile:=msoFalse, _
          savewithdocument:=msoCTrue, Left:=10, Top:=20, width:=100, Height:=50
  </code></pre>
  
  <p>However, I'm struggling to assign the picture to a shape (or other object) so that I can name it and later refer to it. e.g.</p>
  
  <pre><code>Dim shp As Shape
  set shp = ActiveSheet.Shapes.AddPicture Filename:="image.jpg", linktofile:=msoFalse, _
          savewithdocument:=msoCTrue, Left:=10, Top:=20, width:=100, Height:=50
  shp.name = "myPicture"
  
  ... some code ...
  
  ActiveSheet.Shapes("myPicture").Delete ' or similar code to later delete the image 
  </code></pre>
  
  <p>However, I'm getting a syntax error on the <code>set shp = ...</code> line</p>
  
  <p>I've also tried with: <code>Dim shp As Excel.Shape</code>, <code>Dim shp As Object</code> as per the comments in SO post: <a href="https://stackoverflow.com/a/17110977/1448678" title="VBA to insert embeded picture excel">VBA to insert embeded picture excel</a> but still get the syntax errors.  </p>
  
  <p>Where am I going wrong?</p>