title: Word macro to ungroup text boxes
body: <p>I work in a disability services office, and one thing we do fairly frequently is enlarge Word documents which were converted from PDF. To streamline the process, I've been working on "writing" a macro (mostly actually copying and pasting bits from elsewhere or from the macro recorder) to do things like remove extra paragraph breaks or "normalize" the font style/size/spacing/etc.</p>
  
  <p>Often, when we convert a PDF file to a Word file we end up with some of the text in textboxes. I would like to be able to remove text from all text-boxes and replace them with the plain text. I don't care about keeping any formatting for the text at all, or keeping decorative lines and what not. I found some code in my searching that works for text boxes which aren't grouped, but I have a document where the textboxes are grouped.</p>
  
  <p>I found a macro which should ungroup shapes, including textboxes. But when I run the macro, the ungroup line throws an error message; "Run-time error '-2147024891 (80070005)': Group is locked and cannot be ungrouped" I can manually select and ungroup the textboxes UNLESS I've manually set them to be in-line in the document, at which point the "ungroup" selection is grayed-out in the tab. If I copy JUST the textbox to a new document and run the ungroup macro, it works as intended, but only after I manually set the group to something other than in-line. If I leave it as in-line, the macro throws the same error message.</p>
  
  <p>The code in question:</p>
  
  <pre><code>Sub Ungroup
      Dim xNmbr As Integer
      Dim strText As String
      With ActiveDocument
      For xNmbr = .Shapes.Count To 1 Step -1
      .Shapes(xNmbr).Select
      .Shapes(xNmbr).ConvertToInlineShape
      .Shapes(xNmbr).Ungroup
      Next
      End With
  End Sub
  </code></pre>
  
  <p>Anyone know what's going on here? I know there's one other question on here which asks about the same error message but they're working with shapes that aren't text so their solution doesn't work for me.</p>
  
  <p>Here's a sample file that's the same as the one I was trying to edit (I just changed the text; the structure is the same).</p>
  
  <p><a href="https://www.dropbox.com/s/z6ovashu3qv43i9/Fake%20Book.docx?dl=0" rel="nofollow noreferrer">https://www.dropbox.com/s/z6ovashu3qv43i9/Fake%20Book.docx?dl=0</a></p>
  
  <p>Thanks in advance!</p>
  
  <p>ETA -- here's some code that works on my sample document perfectly, but in other documents I've tried it on deletes the text boxes instead of ungrouping them.</p>
  
  <pre><code>Sub Ungroup()
      Dim xNmbr As Integer
      With ActiveDocument
      For xNmbr = .Shapes.Count To 1 Step -1
          .Shapes(xNmbr).Select
          Set thisshape = .Shapes(xNmbr)
      With thisshape.WrapFormat
          .Type = wdWrapSquare
      End With
  Next
  End With
  
  Dim mydocument As Document
      Set mydocument = ActiveDocument
      Dim shp As Shape
      For Each shp In mydocument.Shapes
          If shp.Type = msoGroup Then shp.Ungroup
      Next shp
  End Sub
  </code></pre>