Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Change AutoShape Text Color in VBA?


I have a button on a worksheet which runs some VBA code. Most of it
works fine but when it comes to a section that is supposed to change
the line, fill and font color of an AutoShape ( a rectangle) containing
some text, I have a problem. I can change the line color and fill color
okay with the following code:


Code:
--------------------
'fill color = tan
Shapes("test").Fill.ForeColor.SchemeColor = 47

'line color = black
Shapes("test").Line.ForeColor.SchemeColor = 64
--------------------


However, when I programmed in this code for the font color...


Code:
--------------------
Shapes("test").Font.ColorIndex = 0
--------------------


...I get the error message "object doesn't support this property or
method".

I take this to mean that you cannot change the font color, but this
must be wrong! How can I change the font color if the object doesn't
have the .Font.ColorIndex property?

If I actually select the object on the worksheet then I can record a
macro that will change the color. This is what I get:


Code:
--------------------
Selection.Font.ColorIndex = 0
--------------------


But I don't want to have to select the object in order to change the
font color.

What can I do?

Thanks
-Rob


--
TheRobsterUK


------------------------------------------------------------------------
TheRobsterUK's Profile: http://www.excelforum.com/member.php...fo&userid=9924
View this thread: http://www.excelforum.com/showthread...hreadid=472204

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default Change AutoShape Text Color in VBA?

I don't know how to do this in code - but the font color is set by "Fore
Color" for tool box buttons.

Got the following code by recording a Forms Toolbar button. You can delete
most of it and just get font color...

ActiveSheet.Shapes("Button 2").Select
Selection.Characters.Text = "Button 2"
With Selection.Characters(Start:=1, Length:=8).Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 3 ' <<< Red font
End With

--
steveB

Remove "AYN" from email to respond
"TheRobsterUK"
wrote in message
news:TheRobsterUK.1w6u6d_1128110729.8512@excelforu m-nospam.com...

I have a button on a worksheet which runs some VBA code. Most of it
works fine but when it comes to a section that is supposed to change
the line, fill and font color of an AutoShape ( a rectangle) containing
some text, I have a problem. I can change the line color and fill color
okay with the following code:


Code:
--------------------
'fill color = tan
Shapes("test").Fill.ForeColor.SchemeColor = 47

'line color = black
Shapes("test").Line.ForeColor.SchemeColor = 64
--------------------


However, when I programmed in this code for the font color...


Code:
--------------------
Shapes("test").Font.ColorIndex = 0
--------------------


..I get the error message "object doesn't support this property or
method".

I take this to mean that you cannot change the font color, but this
must be wrong! How can I change the font color if the object doesn't
have the .Font.ColorIndex property?

If I actually select the object on the worksheet then I can record a
macro that will change the color. This is what I get:


Code:
--------------------
Selection.Font.ColorIndex = 0
--------------------


But I don't want to have to select the object in order to change the
font color.

What can I do?

Thanks
-Rob


--
TheRobsterUK


------------------------------------------------------------------------
TheRobsterUK's Profile:
http://www.excelforum.com/member.php...fo&userid=9924
View this thread: http://www.excelforum.com/showthread...hreadid=472204



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Change AutoShape Text Color in VBA?

Note that macros don't always give you the full syntax since they
Select everything. If you want to change the color without selecting
the object then use the following:

Shapes("test").TextFrame.Characters.Font.ColorInde x = 0

The one problem that can occur is if there is no text in the Autoshape.
In that case the line above will throw an error (since there are no
characters). So it's best to precede it with an On Error Resume Next
statement.

HTH,

Nick Hebb
BreezeTree Software
http://www.breezetree.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Change AutoShape Text Color in VBA?


Nick,

That works great, thanks! I've been tearing my hair out for hour
trying to figure out how to change the font colour. You're a lif
saver. :)

Cheers
-Ro

--
TheRobsterU

-----------------------------------------------------------------------
TheRobsterUK's Profile: http://www.excelforum.com/member.php...nfo&userid=992
View this thread: http://www.excelforum.com/showthread.php?threadid=47220

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can Text Function change output text color? epiekarc Excel Discussion (Misc queries) 1 December 31st 08 02:58 AM
fill autoshape color with ref cell conditional formatting Julie Excel Worksheet Functions 1 May 16th 08 05:01 PM
autoshape color conditional formating Dennis Collins Excel Discussion (Misc queries) 11 May 16th 08 01:35 PM
How do I change the autoshape size from inches to cm Francois Excel Discussion (Misc queries) 2 August 12th 06 04:26 PM
Change of text or background color doesn't change on the screen. Susan Excel Discussion (Misc queries) 5 July 29th 05 07:18 PM


All times are GMT +1. The time now is 01:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"