There are several macros around to remove text boxes from a document,
but I cannot find a way to preserve the text inside them.

Can anybody point me to one which actually works?

Thanks a lot

--
John Doue

RE: Removing text boxes while preserving the text inside them by JeanGuyMarcil

JeanGuyMarcil
Thu May 08 10:11:02 PDT 2008

"John Doue" wrote:

> There are several macros around to remove text boxes from a document,
> but I cannot find a way to preserve the text inside them.
>
> Can anybody point me to one which actually works?
>

Dim rngPara As Range
Dim i As Long

With ActiveDocument
If .Shapes.Count > 0 Then
For i = .Shapes.Count To 1 Step -1
If .Shapes(i).Type = msoTextBox Or _
.Shapes(i).Type = msoAutoShape Then
If .Shapes(i).TextFrame.HasText Then
Set rngPara = .Shapes(i).Anchor
rngPara.Collapse wdCollapseStart
rngPara.FormattedText = .Shapes(i) _
.TextFrame.TextRange.FormattedText
.Shapes(i).Delete
End If
End If
Next
End If
End With


Re: Removing text boxes while preserving the text inside them by John

John
Thu May 08 10:40:43 PDT 2008

Jean-Guy Marcil wrote:
> "John Doue" wrote:
>
>> There are several macros around to remove text boxes from a document,
>> but I cannot find a way to preserve the text inside them.
>>
>> Can anybody point me to one which actually works?
>>
>
> Dim rngPara As Range
> Dim i As Long
>
> With ActiveDocument
> If .Shapes.Count > 0 Then
> For i = .Shapes.Count To 1 Step -1
> If .Shapes(i).Type = msoTextBox Or _
> .Shapes(i).Type = msoAutoShape Then
> If .Shapes(i).TextFrame.HasText Then
> Set rngPara = .Shapes(i).Anchor
> rngPara.Collapse wdCollapseStart
> rngPara.FormattedText = .Shapes(i) _
> .TextFrame.TextRange.FormattedText
> .Shapes(i).Delete
> End If
> End If
> Next
> End If
> End With
>
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
experiment a little with it?

Thanks

--
John Doue

Re: Removing text boxes while preserving the text inside them by JeanGuyMarcil

JeanGuyMarcil
Thu May 08 12:13:01 PDT 2008

"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
> experiment a little with it?

You mean you tried my code and it did nothing?
You actually tried it, right?

I just tested it with Word 2003 and all textboxes were removed while
preserving their content (text and format) at the anchor point.

What type of content are you testing this on?



If that is the case, are your textbox floating or inline with the text?

Re: Removing text boxes while preserving the text inside them by John

John
Fri May 09 02:02:09 PDT 2008

Jean-Guy Marcil wrote:
> "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
>> experiment a little with it?
>
> You mean you tried my code and it did nothing?
> You actually tried it, right?
>
> I just tested it with Word 2003 and all textboxes were removed while
> preserving their content (text and format) at the anchor point.
>
> What type of content are you testing this on?
>
>
>
> If that is the case, are your textbox floating or inline with the text?

Jean-Guy,

Yes, I of course did test your macro, it would have been very stupid and
rude of me not to do it!

The best way would be for me to send you an abstract of the document
since I am not sure I can precisely answer your questions. But since I
am not at liberty to publish this document, I need to send it to you
privately. Is this possible?

Best regards

--
John Doue

Re: Removing text boxes while preserving the text inside them by JeanGuyMarcil

JeanGuyMarcil
Fri May 09 05:17:01 PDT 2008

"John Doue" wrote:

> Jean-Guy Marcil wrote:
> > "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
> >> experiment a little with it?
> >
> > You mean you tried my code and it did nothing?
> > You actually tried it, right?
> >
> > I just tested it with Word 2003 and all textboxes were removed while
> > preserving their content (text and format) at the anchor point.
> >
> > What type of content are you testing this on?
> >
> >
> >
> > If that is the case, are your textbox floating or inline with the text?
>
> Jean-Guy,
>
> Yes, I of course did test your macro, it would have been very stupid and
> rude of me not to do it!

Just checking...Your previous message could have been interpreted to mean
that you had already seen a similar macro on the Internet, so you did not
need to test mine...
Also, I have seen strange behaviour from posters... so I now never assume
anything!

> The best way would be for me to send you an abstract of the document
> since I am not sure I can precisely answer your questions. But since I
> am not at liberty to publish this document, I need to send it to you
> privately. Is this possible?

You can send me a few pages that I can test. No guarantee though!
Are you in a hurry over this?

Unscramble this:

"MyFirstName(no hyphen)"_m AT hotmail period com
or
"jeanguy" "underscore" "the letter before N" AT hotmail period com

Cheers.


Re: Removing text boxes while preserving the text inside them by John

John
Tue May 13 01:35:34 PDT 2008

John Doue wrote:
> Jean-Guy Marcil wrote:
>> "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
>>> experiment a little with it?
>>
>> You mean you tried my code and it did nothing?
>> You actually tried it, right?
>>
>> I just tested it with Word 2003 and all textboxes were removed while
>> preserving their content (text and format) at the anchor point.
>>
>> What type of content are you testing this on?
>>
>>
>>
>> If that is the case, are your textbox floating or inline with the text?
>
> Jean-Guy,
>
> Yes, I of course did test your macro, it would have been very stupid and
> rude of me not to do it!
>
> The best way would be for me to send you an abstract of the document
> since I am not sure I can precisely answer your questions. But since I
> am not at liberty to publish this document, I need to send it to you
> privately. Is this possible?
>
> 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

_________________________________________



--
John Doue

Re: Removing text boxes while preserving the text inside them by fumei

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


Re: Removing text boxes while preserving the text inside them by JeanGuyMarcil

JeanGuyMarcil
Tue May 13 10:08:02 PDT 2008

"fumei via OfficeKB.com" wrote:

> 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.
>

That was the price he had to pay...
Thanks for paying John!

Re: Removing text boxes while preserving the text inside them by John

John
Tue May 13 10:58:14 PDT 2008

fumei via OfficeKB.com wrote:
> 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
>>
>> _________________________________________
>>
>

Glad this was of interest to you, I was under the impression this issue
was of limited interest. Did you actually test the code?

Regards

--
John Doue

Re: Removing text boxes while preserving the text inside them by John

John
Tue May 13 11:00:32 PDT 2008

Jean-Guy Marcil wrote:
> "fumei via OfficeKB.com" wrote:
>
>> 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.
>>
>
> That was the price he had to pay...
> Thanks for paying John!
You are welcome, I always try to keep my side of bargains. Did struggle
a few hours to make the code work until I understood - more or less -
what the problem was.

Regards

--
John Doue

Re: Removing text boxes while preserving the text inside them by JeanGuyMarcil

JeanGuyMarcil
Wed May 14 05:39:00 PDT 2008

"John Doue" wrote:

> Jean-Guy Marcil wrote:
> > "fumei via OfficeKB.com" wrote:
> >
> >> 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.
> >>
> >
> > That was the price he had to pay...
> > Thanks for paying John!
> You are welcome, I always try to keep my side of bargains. Did struggle
> a few hours to make the code work until I understood - more or less -
> what the problem was.

For those interested, and also, for those who might be able to exlpain what
happened, because I can't...

The problem was that I sent him some perfectly good code by email (I used
OE, which manages my Hotmail account). When John got it, for some reason, 90%
of the periods "." at the start of lines within With blocks had been
stripped.

So, for example, instead of:

With rngText
.InsertParagraphAfter
.Collapse wdCollapseEnd
.Text = strTextFiller
.Bookmarks.Add strBookName & "1", rngText
.InsertParagraphAfter
.Collapse wdCollapseEnd
End With

He got:

With rngText
InsertParagraphAfter
Collapse wdCollapseEnd
Text = strTextFiller
.Bookmarks.Add strBookName & "1", rngText
InsertParagraphAfter
Collapse wdCollapseEnd
End With

???

Re: Removing text boxes while preserving the text inside them by John

John
Wed May 14 07:34:17 PDT 2008

Jean-Guy Marcil wrote:
> "John Doue" wrote:
>
>> Jean-Guy Marcil wrote:
>>> "fumei via OfficeKB.com" wrote:
>>>
>>>> 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.
>>>>
>>> That was the price he had to pay...
>>> Thanks for paying John!
>> You are welcome, I always try to keep my side of bargains. Did struggle
>> a few hours to make the code work until I understood - more or less -
>> what the problem was.
>
> For those interested, and also, for those who might be able to exlpain what
> happened, because I can't...
>
> The problem was that I sent him some perfectly good code by email (I used
> OE, which manages my Hotmail account). When John got it, for some reason, 90%
> of the periods "." at the start of lines within With blocks had been
> stripped.
>
> So, for example, instead of:
>
> With rngText
> .InsertParagraphAfter
> .Collapse wdCollapseEnd
> .Text = strTextFiller
> .Bookmarks.Add strBookName & "1", rngText
> .InsertParagraphAfter
> .Collapse wdCollapseEnd
> End With
>
> He got:
>
> With rngText
> InsertParagraphAfter
> Collapse wdCollapseEnd
> Text = strTextFiller
> .Bookmarks.Add strBookName & "1", rngText
> InsertParagraphAfter
> Collapse wdCollapseEnd
> End With
>
> ???
Jean-Guy,

As I explained privately to you, the fact is you sent me the code in an
html post. When your post is viewed as original html, some periods do
not show (I found this to be true both with Seamonkey and Thunderbird).

When viewed as text, the periods reappear. So, the reason has to do with
html, and my suggestion is, you post only in text format, which is the
only way I see to make sure such problems do not occur.

But don't ask me why this is happening, I am not an Html expert!

--
John Doue