返回列表 上一主題 發帖

請問如何用鍵盤鍵跟CommandButton有相同功能

回復 5# GBKEE


    Public i As Integer
Sub Ex()
Application.OnKey "{F1}", "Sheet1.CommandButton1_Click"
End Sub

Private Sub CommandButton1_Click()

i = i + 1

        Sheets("sheet1").Cells(i, 1) = "X="
        Sheets("sheet1").Cells(i, 2) = Int((10 * Rnd) + 1)

End Sub
謝謝版大!但還是不成...小輩還有什麼錯?

TOP

回復 2# cdkee
必先執行下面程式
Sub Ex()
Application.OnKey "{F1}", "Sheet1.CommandButton1_Click"
End Sub

TOP

Public i As Integer
Private Sub CommandButton1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = Asc("{F1}") Then
CommandButton1_Click
End If
End Sub


Private Sub CommandButton1_Click()
i = i + 1

        Sheets("sheet1").Cells(i, 1) = "X="
        Sheets("sheet1").Cells(i, 2) = Int((10 * Rnd) + 1)

End Sub
試了這個,也不成功...

TOP

Private Sub CommandButton1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
找到這個,但不懂有沒有關係...

TOP

Public i As Integer

Private Sub CommandButton1_Click()

Application.OnKey "{F1}"
i = i + 1
        Sheets("sheet1").Cells(i, 1) = "X="
        Sheets("sheet1").Cells(i, 2) = Int((10 * Rnd) + 1)

End Sub

試了這個,但不成功...

TOP

        靜思自在 : 世上有兩件事不能等:一、孝順 二、行善。
返回列表 上一主題