title: replace inlineshapes using word VBA
body: <p>I have a word document with many images in it and I wish to be able to select a file path (in which the new images are located and numbered i.e. 1 to 100) to then replace the existing images with the new images. </p>
  
  <p>I have read a few posts of others retrieving the properties of existing inlineshapes to achieve this, but I have also read people succeeding with the following method which seems much simpler (I just haven't been able to get the code working fully yet). Currently the code will run and replace the last image perfectly fine, but then stops with error '438' - Object doesn't support this property or method when it tries to replace the second last image. </p>
  
  <p>The code is as follows:</p>
  
  <pre><code>Sub Replace_images()
    Dim rg As Word.Range
    Dim i As Long
    Dim doc As Word.Document
    Dim path As String
  
   'Ensure pictures are numbered with no leading zeros (in folder) &amp; are .jpg
    path = "C:\filepathtopictures\"
  
     Set doc = ActiveDocument
  
  For i = doc.InlineShapes.Count To 1 Step -1
  
    Set rg = doc.InlineShapes(i).Range
    doc.InlineShapes(i).Delete
    rg = doc.InlineShapes.AddPicture(path &amp; i &amp; ".jpg", False, True, rg)
  
  Next i
  
  End Sub
  </code></pre>
  
  <p>I don't understand how the using the addpicture doesn't work for the next image when nothing has change from the last image. If someone could please explain why it doesn't work or tell me what needs to be changed that would be great!</p>