Search for text box formatted to Layout: In line with text
by RGFuIEI » Thu, 21 Feb 2008 21:15:02 GMT
Hi.
I've managed to set up a macro that hides the content of all text boxes in
my document by searching for each text box and setting the contents' font
colour to white. However, it only seems to find text boxes that haven't been
formatted to 'Layout: In line with text'.
Does anybody know way to search for and edit these text boxes as well as the
others?
Here is the code that I am using:
Sub HideAnswers()
' Find each text box and set it's font colour to white
Dim aShape As Shape
For Each aShape In ActiveDocument.Shapes
If aShape.Type = msoTextBox Then
aShape.Select
Selection.Font.Color = wdColorWhite
End If
Next
End Sub
Any help would be really appreciated.
Cheers,
Dan.
Re: Search for text box formatted to Layout: In line with text
by Stefan Blom » Thu, 21 Feb 2008 22:28:33 GMT
I'm guessing the problem is caused by your attempt to select the text. Use
this code instead:
Sub HideAnswers()
Dim aShape As Shape
For Each aShape In ActiveDocument.Shapes
If aShape.Type = msoTextBox Then
'Set the font color directly for each text box shape:
aShape.TextFrame.ContainingRange.Font.Color = wdColorWhite
End If
Next
End Sub
--
Stefan Blom
Microsoft Word MVP
RE: Search for text box formatted to Layout: In line with text
by SmVhbi1HdXkgTWFyY2ls » Thu, 21 Feb 2008 22:29:02 GMT
Normally, inLine shapes and floating shapes are two different collections.
You would have to iterate both of them. But, textboxes are different, even
when inline they retain their "Shape" status. However, your usage of the
Selection object is causing you grief. Only use the Selection object when you
must (i.e. there is no other way of achieveing a result).
Try this variation of your code:
Dim aShape As Shape
For Each aShape In ActiveDocument.Shapes
If aShape.Type = msoTextBox Then
With aShape
If .TextFrame.HasText Then
.TextFrame.TextRange.Font.Color = wdColorWhite
End If
End With
End If
Next
Re: Search for text box formatted to Layout: In line with text
by SmVhbi1HdXkgTWFyY2ls » Thu, 21 Feb 2008 23:19:01 GMT
Just in case DanB (or other readers) does not know the difference between
our two suggestions I thougth I'd clarify a small technical point...
You used the .ContainingRange property which refers to the entire range of
text inside linked textboxes. I use the .TextRange property which refers to
the individual range of text inside each textbox, whether they are linked or
not. In this case, the only difference in the application is that if there
are, let's say, 3 linked textboxes, the code with the .ContainingRange
Property will apply the white font colour three times to the text inside the
linked textboxes. So, in this case, it does not matter which property one
uses, but with some other scenario, it might make a big difference!
Re: Search for text box formatted to Layout: In line with text
by Stefan Blom » Fri, 22 Feb 2008 21:33:06 GMT
Of course, generally it makes more sense to use .TextRange, since it returns
the range of a *specific* shape (excluding the ranges of any linked
shapes/text boxes). Thank you for adding this clarification.
--
Stefan Blom
Microsoft Word MVP
Similar Threads:
1.Text boxes keep moving after Format:Text Box:Layout:Advanced:
I'm using Word 2008 (12.1.5), OS X 10.5.6. I am trying to having two-column
text flow around tables and figures that I place in text boxes that I am
trying to anchor. After inserting and formatting the text boxes, I find that
revisions to certain text, or changing the spacing between certain text
boxes and the text causes the text box to 'jump' to another page. Only
certain text boxes seem to be 'volatile', but I cannot discern what setting I
may have implemented to cause this.
I use the Format:Text Box:Layout:Advanced path and set the text boxes with
absolute measurements relative to the margins. I have been activating the
'Lock Anchor' option, but no other option. I do not activate the 'Move
object with Text' option. I cannot detect any sign that I inadvertantly
formatted the text to affect the text box position. I cannot extract any
help from the Help.
2.change the layout of the text boxs via format text box window
Engin
"jeffrey" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...
>
> --
> jew
3.Text box formatting moves text box
In normal Word usage I can change the text margins and size of a text box
using the Format Text Box dialogue and the text box stays in the same
position. However, when I try to do the same operations while recording a
macro the text box gets moved to the top left corner of the page when I click
on OK. How can I stop this happening, or at least edit the macro so the
position of the text box is not altered?
Grateful for assistance.
4.How do I stop text in text boxes affecting text in other text box
I create family trees using text boxes in Word. I have a text box on page 1
which seems to be connected mysteriously to a text box on page 15. Whatever
I type in either one comes up in the other. Are they linked? How? Can I stop
it?
5.Typing text is impossibly slow in text boxes when in publishing layout
Version: 2008
Operating System: Mac OS X 10.6 (Snow Leopard)
Processor: Intel
When I try to type or edit text in a text box in a template document (a newsletter template) the typing, editing, deleting, backspacing or what ever, is absolutely impossibly slow. Am I doing something wrong or do I have something set up wrong. If it remains this way I will not be able to work in this program.
6. layout wrapping text around text boxes in word 2000
7. Displaying Text With Layout in a Text Box
8. Searching for text in Text boxes