Extracting the contents of textboxes into a new document Wordfast Classic
Q: I want to run a word count of all the text contained in textboxes in my document.
A: Run the following macro. It will create a new document containing all text found in textboxes.
Sub ExtractFromTextBoxes()
Dim I As Integer, J as Integer, Boite As Variant, ThisDoc As Document
ActiveWindow.View.Type = wdPrintView
Set ThisDoc = ActiveDocument
DocName = ThisDoc.FullName
Documents.Add
On Local Error Resume Next
' Convert InlineShapes (anchored shapes) to regular shapes
For Each Boite In ThisDoc.InlineShapes
Boite.ConvertToShape
Next
' I > 0 indicates there are still ungrouped textboxes to process
' J is just a security to avoid looping endlessly.
I = 1: J = 0
While I > 0 And J < 10000
' Ungroup grouped shapes
For Each Boite In ThisDoc.Shapes
Boite.Ungroup
Next
' make sure all textboxes were ungrouped
' (embedded groupings may need more than one pass to be ungrouped)
For Each Boite In ThisDoc.Shapes
I = 0: I = Boite.GroupItems.Count
If I > 0 Then Exit For
Next
J = J + 1
Wend
For Each Boite In ThisDoc.Shapes
With Boite.TextFrame
If a textbox has text, copy it into the empty document
If .HasText Then
Selection.InsertAfter .TextRange
Selection.InsertParagraphAfter
Selection.Start = Selection.End
End If
End With
Next
' Ungrouping usually creates a mess:
' close the original document without saving it
ThisDoc.Close 0
End Sub
Back to Wordfast Classic User Manual