Forum

Changing shape colo...
 
Notifications
Clear all

Changing shape colours

8 Posts
4 Users
0 Reactions
91 Views
(@lanser)
Posts: 61
Estimable Member
Topic starter
 

Hi I have a sheet with a lot of shapes on some of whic I am using as buttons I tried a short piece of code to fade the text of the clicked shape but it gives a type mismatch error on the If line

 

Sub ClickedBtn()
Dim shp As Shape

For Each shp In ActiveSheet.Shapes
If shp.Name = "btn_Hetton" Or "btn_GMH" Or "btn_Kibi" Or "btn_MHarb" Or "btn_All" Then
shp.Fill.BackColor.RGB = RGB(0, 0, 0)
Else
End If

Next shp
ActiveSheet.Shapes(Application.Caller).Fill.BackColor.RGB = RGB(192, 192, 192)

End Sub

 
Posted : 18/03/2023 1:50 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi,

Please supply your file so we don't have to recreate it.

Thanks

Phil

 
Posted : 18/03/2023 9:23 pm
(@lanser)
Posts: 61
Estimable Member
Topic starter
 

File attached it has links to ther files so graphs wont change but everything else should work

 
Posted : 21/03/2023 4:47 am
(@debaser)
Posts: 836
Member Moderator
 

You can't write Or criteria like that - you have to repeat the test of the shape name each time.

If shp.Name = "btn_Hetton" Or shp.Name = "btn_GMH" Or shp.Name = "btn_Kibi" Or shp.Name = "btn_MHarb" Or shp.Name = "btn_All"

Alternatively, use a Select Case construction:

 

For Each shp In ActiveSheet.Shapes
Select Case shp.Name
Case "btn_Hetton", "btn_GMH", "btn_Kibi", "btn_MHarb", "btn_All"
shp.Fill.BackColor.RGB = RGB(0, 0, 0)
Case Else
' do nothing
End Select

Next shp

 
Posted : 21/03/2023 5:28 am
(@lanser)
Posts: 61
Estimable Member
Topic starter
 

Thanks,

I tried with the case select but it doesnt appear to do anything it runs but doesnt change font and skips over the Application.Caller Shape

 
Posted : 21/03/2023 12:26 pm
(@debaser)
Posts: 836
Member Moderator
 

There is no code there to change font?

 

Application.Caller will only work if the code is called by clicking a button.

 
Posted : 21/03/2023 1:51 pm
(@keebellah)
Posts: 373
Reputable Member
 

And the file will also not work if there are unresolved references because it points either to a renamed file of an entire different file.

When posting a file make sure it works for the perosons outside your environment

e.g.

 

='Z:Daten5_Werksorganisation2_QSMGB_57_ComplaintsCustomerCopy of Customer Complaint Log 20222.xlsx'!CompLog[Comp number]

 
Posted : 22/03/2023 3:54 am
(@lanser)
Posts: 61
Estimable Member
Topic starter
 

I mistyped its the back color thats supposed to change, but I now changed it to forecolor and it works.

thanks

 
Posted : 23/03/2023 6:20 am
Share: