Change the text of shapes automatically

Mustafa Alfahad

New Member
Joined
Mar 30, 2020
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi Everyone,

these shapes below I make it as a button for changing data when press on it, my question is I need to change the text color of shape once press one of them (using a macro), also when press to another shapes the color followed and be the other as the same original color.

1585585627453.png
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Welcome to the Board

You will have to adapt the existing code for each button to run under this new structure, tell me if you need help with that.

VBA Code:
Sub Run_Me()
Dim i%
For i = 1 To ActiveSheet.Shapes.Count
    ActiveSheet.Shapes(i).OnAction = "ShClick"
Next
End Sub

Sub ShClick()           ' this one runs automatically
Dim cob As Object, t, i%, sht As Worksheet
Set sht = ActiveSheet
Set cob = sht.Shapes(Application.Caller)
On Error Resume Next
t = cob.TextFrame2.TextRange.Text
If Err.Number <> 0 Then Exit Sub
cob.Fill.ForeColor.RGB = RGB(110, 200, 120)
cob.TextFrame.Characters.Font.Color = RGB(220, 10, 50)
For i = 1 To sht.Shapes.Count
    If cob.Name <> sht.Shapes(i).Name Then
        sht.Shapes(i).Fill.ForeColor.RGB = RGB(250, 250, 250)
        sht.Shapes(i).TextFrame.Characters.Font.Color = RGB(5, 5, 5)
    End If
Next
End Sub
 
Upvote 0
The complete version:

VBA Code:
Sub Run_Me()
Dim i%
For i = 1 To ActiveSheet.Shapes.Count
    ActiveSheet.Shapes(i).OnAction = "'ShClick """ & i & """'"
Next
End Sub

Sub ShClick(j%)           ' this one runs automatically
Dim cob As Object, t, i%, sht As Worksheet
Set sht = ActiveSheet
Set cob = sht.Shapes(Application.Caller)
On Error Resume Next
t = cob.TextFrame2.TextRange.Text
If Err.Number <> 0 Then Exit Sub
cob.Fill.ForeColor.RGB = RGB(110, 200, 120)
cob.TextFrame.Characters.Font.Color = RGB(220, 10, 50)
For i = 1 To sht.Shapes.Count
    If cob.Name <> sht.Shapes(i).Name Then
        sht.Shapes(i).Fill.ForeColor.RGB = RGB(250, 250, 250)
        sht.Shapes(i).TextFrame.Characters.Font.Color = RGB(5, 5, 5)
    End If
Next
On Error GoTo 0
Select Case j
    Case 1: Task1
    Case 2: Task2
    Case 3: Task3
End Select
End Sub

Sub Task1()
MsgBox "Code for button 1"
End Sub

Sub Task2()
MsgBox "Code for button 2"
End Sub

Sub Task3()
MsgBox "Code for button 3"
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top