我在窗体的按钮。我不想写每一个按钮的功能“更新后”,因为每将会是相似的。就是这样,使它比写单按钮功能单一简单?
Sub button1_afterUpdate()
End sub
Sub button2_afterUpdate()
'............
'The same code as button1 function
'...........
End sub
一个简单的方法是创建为实际的代码是每个按钮的同子:
Sub RunThisForEveryButton_afterUpdate()
'This is the same code that should run in every button
End Sub
然后调用此子在每一个事件...
Sub button1_afterUpdate()
RunThisForEveryButton_afterUpdate
End sub
Sub button2_afterUpdate()
RunThisForEveryButton_afterUpdate
End sub
另一种方法是创建一个使用WithEvents
所有按钮一个事件。因此,看看这里VBA: Using WithEvents on UserForms。