PPT 2003: How to set background color for text in a textbox?


D

Dave Jenkins

Let me see if I can explain this without confusing both of us:

I have vba code that creates a textbox. When the textbox is created and the
user begins to enter text, the entire text frame turns white, and the text
color is taken from defaults (I guess -- at any rate, it's certainly not the
color I specify in the code when I create the textbox). If the textbox is
created with some default text in it, the text is displayed (in my test case)
as white on a black background.

As soon as the user quits entering text (by selecting something else, say),
the textframe background/fill reverts to the fill color for the entire
textbox and the text itself changes to the color specified in the code for
text in the shape.

This only happens in PPT 2003 - in 2007 all operations behaves as expected
(or at least as desired) regardless of whether the textbox is created with
defaulted text in it or not.

My question is: in PPT 2003, is there any way to create a textbox with red
fill, say, and specify white text, and have the text appear as white on a red
backgound when the text is being entered?

Here's some code that I've been using. I'm sure that for testing purposes
more of it could be deleted, but I haven't started going through that
exercise yet.


Sub TextboxTest()

Dim tBoxSh As Shape
Dim oTxtRng As TextRange

' Inserts black-bordered text box with red fill, and sets the font as Ariel
Narrow at 12 pt, with white text.

Set tBoxSh =
ActiveWindow.View.Slide.Shapes.AddTextbox(msoTextOrientationHorizontal,
-16.375, 120.75, 240!, 30!)
With tBoxSh

' fill parameters
.Fill.Visible = msoTrue
.Fill.Solid
.Fill.ForeColor.RGB = RGB(255, 0, 0)
.Fill.Transparency = 0#

' line parameters
.Line.Weight = 2#
.Line.Visible = msoTrue
.Line.ForeColor.RGB = RGB(0, 0, 0)

With .TextFrame
.WordWrap = msoTrue
.AutoSize = ppAutoSizeShapeToFitText
.MarginBottom = 6
.MarginLeft = 6
.MarginRight = 6
.MarginTop = 6

With .TextRange

' here's where I can populate the textbox with soem default stuff
.text = "default text"

With .Font
.name = "Arial Narrow"
.Size = 18
.BaselineOffset = 0
.Color.RGB = RGB(Red:=255, Green:=255, Blue:=255)

End With ' .font
End With ' .textrange
End With ' .textframe

End With ' ActiveWindow.Selection.ShapeRange(1)

' this code here in an attempt to create an visible iinsertion bar at the
start of text
Set oTxtRng = tBoxSh.TextFrame.TextRange
oTxtRng.Characters(oTxtRng.Start + oTxtRng.length, 0).Select

Exit Sub

End Sub
 
Ad

Advertisements

D

Dave Jenkins

I have greatly simplified the test code and it can be found below. I have
also discovered the proximal cause of the weird results I'm getting: they're
caused by the choice of color used for the text. (Really. See comments in
code under "with .font".) I can live with that, because all I have to do is
adjust the colors I'll be using and all will be well. However, I *would*
like to know exactly what's going on -- can someone fill me in?

Dave Jenkins said:
Let me see if I can explain this without confusing both of us:

I have vba code that creates a textbox. When the textbox is created and the
user begins to enter text, the entire text frame turns white, and the text
color is taken from defaults (I guess -- at any rate, it's certainly not the
color I specify in the code when I create the textbox). If the textbox is
created with some default text in it, the text is displayed (in my test case)
as white on a black background.

As soon as the user quits entering text (by selecting something else, say),
the textframe background/fill reverts to the fill color for the entire
textbox and the text itself changes to the color specified in the code for
text in the shape.

This only happens in PPT 2003 - in 2007 all operations behaves as expected
(or at least as desired) regardless of whether the textbox is created with
defaulted text in it or not.

My question is: in PPT 2003, is there any way to create a textbox with red
fill, say, and specify white text, and have the text appear as white on a red
backgound when the text is being entered?

Here's some code that I've been using. I'm sure that for testing purposes
more of it could be deleted, but I haven't started going through that
exercise yet.

[snip]

Test code (mind the word wraps):

Sub test()

Dim tBoxSh As Shape
Dim oTxtRng As TextRange

Set tBoxSh =
ActiveWindow.View.Slide.Shapes.AddTextbox(msoTextOrientationHorizontal,
-16.375, 120.75, 240!, 30!)
With tBoxSh

' fill parameters
.Fill.Visible = msoTrue
.Fill.Solid
.Fill.ForeColor.RGB = RGB(255, 0, 0)
.Fill.Transparency = 0#


With .TextFrame

With .TextRange
.Text = "abcd"

With .Font

' the RGB values chosen appear to drive the problem (but only in PPT 2003)
' with a choice of 0, 0, 0 the problem occurs, as it does with, say, 0, 0,
1.
' With the values below, the program behaves as desired.

.Color.RGB = RGB(Red:=100, Green:=100, Blue:=100)

End With ' .font
End With ' .textrange
End With ' .textframe

End With ' ActiveWindow.Selection.ShapeRange(1)

Set oTxtRng = tBoxSh.TextFrame.TextRange
oTxtRng.Characters(oTxtRng.Start + oTxtRng.Length, 0).Select

Exit Sub

End Sub
 
J

John Wilson

If I'm reading you right Dave what you need is a "normal" feature in 2003. If
you add the text box manually do you not see exactly the same.

The "highlight" color is supposed to aid legibilty and depends on the text
color / fill color and background color (in a complex way I don't understand)
The sample that works has hit on a grey that doesn't change the highlight
color.

As far as I can tell greys don't usually change the highlight unless PPT
thinks they are near white / near black. Try 235,235,235 as your RGB that's
pretty close to white but I think still grey to PPT.
--
Amazing PPT Hints, Tips and Tutorials

http://www.PPTAlchemy.co.uk
http://www.technologytrish.co.uk
email john AT technologytrish.co.uk


Dave Jenkins said:
I have greatly simplified the test code and it can be found below. I have
also discovered the proximal cause of the weird results I'm getting: they're
caused by the choice of color used for the text. (Really. See comments in
code under "with .font".) I can live with that, because all I have to do is
adjust the colors I'll be using and all will be well. However, I *would*
like to know exactly what's going on -- can someone fill me in?

Dave Jenkins said:
Let me see if I can explain this without confusing both of us:

I have vba code that creates a textbox. When the textbox is created and the
user begins to enter text, the entire text frame turns white, and the text
color is taken from defaults (I guess -- at any rate, it's certainly not the
color I specify in the code when I create the textbox). If the textbox is
created with some default text in it, the text is displayed (in my test case)
as white on a black background.

As soon as the user quits entering text (by selecting something else, say),
the textframe background/fill reverts to the fill color for the entire
textbox and the text itself changes to the color specified in the code for
text in the shape.

This only happens in PPT 2003 - in 2007 all operations behaves as expected
(or at least as desired) regardless of whether the textbox is created with
defaulted text in it or not.

My question is: in PPT 2003, is there any way to create a textbox with red
fill, say, and specify white text, and have the text appear as white on a red
backgound when the text is being entered?

Here's some code that I've been using. I'm sure that for testing purposes
more of it could be deleted, but I haven't started going through that
exercise yet.

[snip]

Test code (mind the word wraps):

Sub test()

Dim tBoxSh As Shape
Dim oTxtRng As TextRange

Set tBoxSh =
ActiveWindow.View.Slide.Shapes.AddTextbox(msoTextOrientationHorizontal,
-16.375, 120.75, 240!, 30!)
With tBoxSh

' fill parameters
.Fill.Visible = msoTrue
.Fill.Solid
.Fill.ForeColor.RGB = RGB(255, 0, 0)
.Fill.Transparency = 0#


With .TextFrame

With .TextRange
.Text = "abcd"

With .Font

' the RGB values chosen appear to drive the problem (but only in PPT 2003)
' with a choice of 0, 0, 0 the problem occurs, as it does with, say, 0, 0,
1.
' With the values below, the program behaves as desired.

.Color.RGB = RGB(Red:=100, Green:=100, Blue:=100)

End With ' .font
End With ' .textrange
End With ' .textframe

End With ' ActiveWindow.Selection.ShapeRange(1)

Set oTxtRng = tBoxSh.TextFrame.TextRange
oTxtRng.Characters(oTxtRng.Start + oTxtRng.Length, 0).Select

Exit Sub

End Sub
 
J

John Wilson

Hey 236,236,236 doesn't work!!!! Go figure
--
Amazing PPT Hints, Tips and Tutorials

http://www.PPTAlchemy.co.uk
http://www.technologytrish.co.uk
email john AT technologytrish.co.uk


Dave Jenkins said:
Hi John:

Thanks for the clarification. I guess I'll just chalk this up to one of
those unexpected, undocumented quirks in PPT that causes one to veer off the
development track for a few hours every now and then.

Yes, I finally tried creating the textbox manually and also saw the results
of the text color variations there. I wasted an inordinate amount of time
examining my code, since years of experience have taught me that that's where
the problem generally lies! I had already stumbled on the 235, 235, 235,
solution last night. It's a very touchy algorithm that 2003 uses - 240, 240,
240 does *not* work, IIRC.
--
Dave Jenkins
K5KX


John Wilson said:
If I'm reading you right Dave what you need is a "normal" feature in 2003. If
you add the text box manually do you not see exactly the same.

The "highlight" color is supposed to aid legibilty and depends on the text
color / fill color and background color (in a complex way I don't understand)
The sample that works has hit on a grey that doesn't change the highlight
color.

As far as I can tell greys don't usually change the highlight unless PPT
thinks they are near white / near black. Try 235,235,235 as your RGB that's
pretty close to white but I think still grey to PPT.
--
Amazing PPT Hints, Tips and Tutorials

http://www.PPTAlchemy.co.uk
http://www.technologytrish.co.uk
email john AT technologytrish.co.uk


Dave Jenkins said:
I have greatly simplified the test code and it can be found below. I have
also discovered the proximal cause of the weird results I'm getting: they're
caused by the choice of color used for the text. (Really. See comments in
code under "with .font".) I can live with that, because all I have to do is
adjust the colors I'll be using and all will be well. However, I *would*
like to know exactly what's going on -- can someone fill me in?

:

Let me see if I can explain this without confusing both of us:

I have vba code that creates a textbox. When the textbox is created and the
user begins to enter text, the entire text frame turns white, and the text
color is taken from defaults (I guess -- at any rate, it's certainly not the
color I specify in the code when I create the textbox). If the textbox is
created with some default text in it, the text is displayed (in my test case)
as white on a black background.

As soon as the user quits entering text (by selecting something else, say),
the textframe background/fill reverts to the fill color for the entire
textbox and the text itself changes to the color specified in the code for
text in the shape.

This only happens in PPT 2003 - in 2007 all operations behaves as expected
(or at least as desired) regardless of whether the textbox is created with
defaulted text in it or not.

My question is: in PPT 2003, is there any way to create a textbox with red
fill, say, and specify white text, and have the text appear as white on a red
backgound when the text is being entered?

Here's some code that I've been using. I'm sure that for testing purposes
more of it could be deleted, but I haven't started going through that
exercise yet.

[snip]

Test code (mind the word wraps):

Sub test()

Dim tBoxSh As Shape
Dim oTxtRng As TextRange

Set tBoxSh =
ActiveWindow.View.Slide.Shapes.AddTextbox(msoTextOrientationHorizontal,
-16.375, 120.75, 240!, 30!)
With tBoxSh

' fill parameters
.Fill.Visible = msoTrue
.Fill.Solid
.Fill.ForeColor.RGB = RGB(255, 0, 0)
.Fill.Transparency = 0#


With .TextFrame

With .TextRange
.Text = "abcd"

With .Font

' the RGB values chosen appear to drive the problem (but only in PPT 2003)
' with a choice of 0, 0, 0 the problem occurs, as it does with, say, 0, 0,
1.
' With the values below, the program behaves as desired.

.Color.RGB = RGB(Red:=100, Green:=100, Blue:=100)

End With ' .font
End With ' .textrange
End With ' .textframe

End With ' ActiveWindow.Selection.ShapeRange(1)

Set oTxtRng = tBoxSh.TextFrame.TextRange
oTxtRng.Characters(oTxtRng.Start + oTxtRng.Length, 0).Select

Exit Sub

End Sub
 
R

Robert L

I am trying to modify the backcolor for a text box control on a slide....
Why can I change the text for the control, but I cannot change the forecolor
or backcolor?
 
Ad

Advertisements

S

Steve Rindsberg

Robert L said:
I am trying to modify the backcolor for a text box control on a slide....
Why can I change the text for the control, but I cannot change the forecolor
or backcolor?

OLEControls don't have the same properties as PPT shapes.
Rightclick the control, choose Properties ... you can set the background and
foreground colors there.
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top