title: Extracting images from Word document using VBA
body: <p>I need to loop over some word documents, and extract images from a word document and save them in a separate folder.
  I've tried the method of saving them as an HTML document, but it is not a good fit for my requirement.</p>
  <p>Now, I'm looping through the images using inlineshapes object and then copy-pasting them on a publisher document and then saving them as an image. However, I'm facing a Runtime Automation error when I'm running the script.
  For using the Publisher runtime library I've tried both early and late binding but I'm facing the error on both of them.</p>
  <p>Can anyone please let me know what is the problem? Also, if anyone can explain why I'm facing this error, that'd be great. As per my understanding, it is due to memory allocation, but I'm not sure.</p>
  <p>Here is the code block that I've been working on (fp, dp are folder paths, while filename is the word document name. I'm calling this sub in another sub that is looping over all the files in a folder):</p>
  <pre><code>Sub test(ByVal fp As String, ByVal dp As String, ByVal filename As String)
  Dim doc As Document
  Dim pubdoc As New Publisher.Document
  Dim shp As InlineShape
  'Application.Screenupdating = False
  'Dim pubdoc As Object
  'Set pubdoc = CreateObject(&quot;Publisher.Document&quot;)
  Set doc = Documents.Open(fp)
  With doc
      i = .InlineShapes.Count
      Debug.Print i
  End With
  For j = 1 To i
      Set shp = doc.InlineShapes(j)
      shp.Select
      Selection.CopyAsPicture
      pubdoc.Pages(1).Shapes.Paste
      pubdoc.Pages(1).Shapes(1).SaveAsPicture (dp &amp; Application.PathSeparator &amp; j &amp; &quot;.jpg&quot;)
      pubdoc.Pages(1).Shapes(1).Delete
  Next
  doc.Close (wdDoNotSaveChanges)
  pubdoc.Close
  'Application.Screenupdating = True
  
  End Sub
  </code></pre>
  <p>Apart from this, if anyone has any suggestions to make this faster, I'm all ears. Thanks in advance!</p>