Changing a shapes fill color when worksheet opens

OfficeUser

Well-known Member
Joined
Feb 4, 2010
Messages
544
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
This is the code that is triggered by a button to alert a user that two specific cells are active:
Code:
Private Sub lblChem_Click()
ActiveSheet.Unprotect Password:="password"
    If Shapes("Oval 1").Fill.ForeColor.SchemeColor = 10 Then 'Red
    Shapes("Oval 1").Fill.ForeColor.SchemeColor = 11
        Range("AW10:BA10,S10:W10").Select
        Selection.Locked = False
Range("AC5").Select
Else
    If Shapes("Oval 1").Fill.ForeColor.SchemeColor = 11 Then 'Green
    Shapes("Oval 1").Fill.ForeColor.SchemeColor = 10
        Range("AW10:BA10,S10:W10").Select
        Selection.Locked = True
Range("AC5").Select
End If
End If
ActiveSheet.Protect Password:="password"
End Sub
If the shape appears red then the cells are locked, when it is green, they are unlocked.

I tried to add this bit into the Workbook_Open event to make sure the two cells are locked and the shape is red when first opening the workbook but I get an error:
Code:
Private Sub Workbook_Open()
ActiveSheet.Unprotect.Password:="password"
If Shapes("Oval 1").Fill.ForeColor.SchemeColor = 11 Then 'Green
    Shapes("Oval 1").Fill.ForeColor.SchemeColor = 10
        Range("AW10:BA10,S10:W10").Select
        Selection.Locked = True
Range("AC5").Select
End If
ActiveSheet.Protect Password:="password"
End Sub
Problem is I receive a compile error: Sub or Function not defined. The highlighted word is 'Shapes'. Anyone know what I am missing? Thanks.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Great, it worked. But why do I not need that in the macro for the button I created?
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,762
Members
452,940
Latest member
rootytrip

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