fumei
Tue May 13 09:33:28 PDT 2008
John, thank you for doing a follow up. Not only with actual working code,
but also an explanation for what was the problem. Very good. Appreciated.
Kudos to Jean-Guy as well of course.
John Doue wrote:
>>>> Thanks Guy, but this is one I had tested which appears to do nothing:
>>>> no error messages, nothing (word 03). Is there some way you could
>[quoted text clipped - 21 lines]
>>
>> Best regards
>
>As a follow up to this thread, Jean-Guy was kind enough to let me email
>him an abstract of the problem document. It appears, the problem was,
>textboxes in it were grouped, which prevented the macro from working.
>
>Jean-Guy emailed me a macro which does the trick of ungrouping these
>grouped boxes, saving the text and removing the boxes. This macro will
>of course also work if the text boxes are not grouped.
>
>The macro I am posting hereunder incorporates limited changes I made to
>the one Jean-Guy emailed me, so if you find any problem with it, I am to
>blame and not Jean-Guy.
>
>Regards
>__________________________________________
>Option Explicit
>
>Sub test()
>
>Dim rngText As Range
>Dim shpText As Shape
>Dim i As Long
>Dim j As Long
>
>'To speed things up a bit, especially if you lots of textboxes.
>Application.ScreenUpdating = False
>
>With ActiveDocument
> For i = .Shapes.Count To 1 Step -1
> If .Shapes(i).Type = msoGroup Then
> j = .Shapes(i).GroupItems.Count
> .Shapes(i).Ungroup
> 'As we ungroup, the number of shapes increases, we have to
>adjust
> 'Also, there might be groups within groups...
> i = i + (j - 1)
> End If
> Next
> For Each shpText In .Shapes
> With shpText
> If .Type = msoTextBox Then
> If .TextFrame.HasText Then
> Set rngText = .Anchor.Paragraphs(1).Range
> With rngText
> .Collapse Direction:=wdCollapseEnd
> .FormattedText = shpText.TextFrame _
> .TextRange.FormattedText
> End With
> shpText.Delete
> End If
> End If
> End With
> Next
>End With
>
>Application.ScreenRefresh
>Application.ScreenUpdating = True
>
>End Sub
>
>_________________________________________
>
--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/200805/1