title: VB.Net how to copy a page from MS Word with image
body: <p>I need to split a ms word document into a separate document for each page.<br>
  I have the following code, but it fails when a page ONLY contains an image.<br>
  For example.. page 1 and 2 contains text, page 3 and 4 contains a single image each. I need page 3 and 4 to be saved as a single document each as well as page 1 and 2<br>
  The line it fails on is:  </p>
  
  <pre><code>WordApp.Selection.Copy()
  </code></pre>
  
  <p>With error:<br>
  <strong>System.Runtime.InteropServices.COMException: This method or property is not available because no text is selected.</strong></p>
  
  <pre><code>Private Sub ParseWordDoc(ByVal FileName As String, ByVal NewFileName As String)
          Dim WordApp As Microsoft.Office.Interop.Word.Application = New Microsoft.Office.Interop.Word.Application()
          Dim BaseDoc As Microsoft.Office.Interop.Word.Document
          Dim DestDoc As Microsoft.Office.Interop.Word.Document
  
          Dim intnumberOfPages As Integer
          Dim intNumberOfChars As String
          Dim intPage As Integer
  
          'Word Constants
          Const wdGoToPage = 1
          Const wdStory = 6
          Const wdExtend = 1
          Const wdCharacter = 1
  
          'Show WordApp
          WordApp.ShowMe()
  
          'Load Base Document
          BaseDoc = WordApp.Documents.Open(Filename)
          BaseDoc.Repaginate()
  
          'load base document
          BaseDoc = WordApp.Documents.Open(FileName)
          BaseDoc.Repaginate()
  
          'loop through pages
          intnumberOfPages = BaseDoc.BuiltInDocumentProperties("Number Of Pages").Value
          intNumberOfChars = BaseDoc.BuiltInDocumentProperties("Number Of Characters").Value
  
          For intPage = 1 To intnumberOfPages
              If intPage = intnumberOfPages Then
                  WordApp.Selection.EndKey(wdStory)
              Else
                  WordApp.Selection.GoTo(wdGoToPage, 2)
                  Application.DoEvents()
  
                  WordApp.Selection.MoveLeft(Unit:=wdCharacter, Count := 1)
              End If
  
              Application.DoEvents()
  
              WordApp.Selection.HomeKey(wdStory, wdExtend)
              Application.DoEvents()
  
              WordApp.Selection.Copy()
              Application.DoEvents()
  
              DestDoc = WordApp.Documents.Add
              DestDoc.Activate()
              WordApp.Selection.Paste()
              DestDoc.SaveAs("E:\0099-Education\WordAutomate_Sln\WordAutomate\bin\Debug\" &amp; NewFileName &amp; intPage.ToString() &amp; ".docx")
              DestDoc.Close()
              DestDoc = Nothing
  
              WordApp.Selection.GoTo(wdGoToPage, 2)
              Application.DoEvents()
  
              WordApp.Selection.HomeKey(wdStory, wdExtend)
              Application.DoEvents()
  
              WordApp.Selection.Delete()
              Application.DoEvents()
          Next
  
          BaseDoc.Close()
          BaseDoc = Nothing
  
          WordApp.Quit()
          WordApp = Nothing
  
      End Sub
  </code></pre>