简体   繁体   中英

Change button colors in VBA when a userform is submitted

First off I apologize if this is a repeat question, I couldn't seem to find an answer but I could be searching wrong.

I have a selection of shapes which I want to change the color of. When clicked they pull up a userform. When the userform is submitted, I want to change the color of the shape from red to green (to indicate it's completion).

I Initially record information from the userform & the name of the shape in a separate worksheets (Record Sheet) I then want to change the color of that shape that was clicked.

Sub SubmitButton_Click()
Dim RecordSheet As Worksheet
Dim BottomRow As Integer
Dim ButtonText As String

Set RecordSheet = Worksheets("Record Sheet")

BottomRow = WorksheetFunction.CountA(RecordSheet.Range("A:A")) + 1
ButtonText = Application.Caller

RecordSheet.Cells(BottomRow, 1) = Now()
RecordSheet.Cells(BottomRow, 2) = ButtonText
RecordSheet.Cells(BottomRow, 3) = IssuesTextBox.Value
If No.Value = True Then
RecordSheet.Cells(BottomRow, 4) = "No"
Else
RecordSheet.Cells(BottomRow, 4) = "Yes"

End If

'Changing the color of the shape that was clicked here

Unload Me

End Sub

Assuming the shape is a regular excel shape that you've linked to a macro ... save the original sheet and shape you've clicked, execute your code ... and then change the shape's fill color ... something like ...

Sub ShapeSubmitButton_Click()

    Dim vSheet As Worksheet
    Dim vShape As Shape

    Set vSheet = ActiveSheet
    Set vShape = vSheet.Shapes(Application.Caller)

    ' YOUR CODE HERE ....

    vShape.Fill.ForeColor.RGB = rgbGreen

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM