PDA

View Full Version : Solved: Change color and text of an Autoshape



pegbol
05-14-2005, 07:53 AM
.
.

Hello,

How can change the text and color of an autoshape when click and run a macro ?.

Example:
When clik button (Letter A) insert A in cell B3, and change the color and text of the same button to color green and text (Letter B).
Then, the next time when click button (Letter B) insert B in cell B3, and change the color and text of the button to color red and text (Letter A).

All with the same button.



I enclose a file with my example.

Thanks in advance for your kind help.

best regards,
Pedro
.
.

johnske
05-14-2005, 08:42 AM
Hi pegbol,

Try this (you can also assign the macro to the autoshape so it changes when you click on it)
Sub ChangeIt()
ActiveSheet.Shapes("AutoShape 1").Select
With Selection
If .ShapeRange.Fill.ForeColor.SchemeColor = 57 Then
GoTo LetterA
Else
GoTo LetterB
End If
LetterA:
.ShapeRange.Fill.ForeColor.SchemeColor = 2
.Characters.Text = "LETTER" & Chr(10) & "A"
[B3] = "B"
Exit Sub
LetterB:
.ShapeRange.Fill.ForeColor.SchemeColor = 57
.Characters.Text = "LETTER" & Chr(10) & "B"
[B3] = "A"
End With
End Sub

HTH,
John

Bob Phillips
05-14-2005, 08:48 AM
.How can change the text and color of an autoshape when click and run a macro ?

Hi Pedro,

Replace your macro with this

Sub letter()
Dim sNext As String
Application.ScreenUpdating = False
ActiveSheet.Shapes("Autoshape 1").Select
With Selection
With .ShapeRange.Fill.ForeColor
If .SchemeColor = 17 Then
Range("B3").FormulaR1C1 = "B"
.SchemeColor = 10
sNext = "A"
Else
Range("B3").FormulaR1C1 = "A"
.SchemeColor = 17
sNext = "B"
End If
End With
With .Characters(8, 1)
.Text = sNext
With .Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 24
End With
End With
End With
ActiveCell.Select
Application.ScreenUpdating = True
End Sub

pegbol
05-14-2005, 09:19 AM
.
.
Thanks you so much johnske and xld!!!!!



best and kind regards,
Pedro
.
.