Excel VBA - How to Change Shape Color on Click
Автор: InAnOffice
Загружено: 2025-03-31
Просмотров: 199
In this tutorial, learn how to use Excel VBA to change the color of a shape when it's clicked, while resetting the colors of all other shapes on the worksheet. This simple VBA script allows you to add interactive features to your Excel workbook, making it easier to visually highlight shapes as you click on them.
Make sure to like, subscribe, and click the bell icon to get notified of more Excel tips and VBA tutorials!
#ExcelVBA #ExcelShapes #ExcelTutorial #ExcelTips #excelautomationtutorial
Dim lastClickedShape As String
Sub Shape_Clicked()
Dim shp As Shape
Dim clickedShape As Shape
Dim clickedShapeName As String
clickedShapeName = ActiveSheet.Shapes(Application.Caller).Name ' Get the name of the clicked shape
' Loop through all shapes on the active sheet
For Each shp In ActiveSheet.Shapes
If shp.Name = clickedShapeName Then
' Change the color of the clicked shape
shp.Fill.ForeColor.RGB = RGB(0, 255, 0) ' Change to Green
Else
'Reset the color of all other shapes
shp.Fill.ForeColor.RGB = RGB(255, 0, 0) ' Reset other shapes to Red
End If
Next shp
End Sub

Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: