返回列表 上一主題 發帖

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

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

本帖最後由 cdkee 於 2010-10-6 18:00 編輯

Public i As Integer

Private Sub CommandButton1_Click()

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

End Sub

請教大大,按鍵盤鍵(例如"F1")跟按CommandButton1有相同功能,是怎樣寫成的?謝謝!

回復 14# GBKEE


    謝謝版大多方提點!

TOP

回復 13# cdkee
要達到一個結果的程式碼 寫法不一定都是一樣的 自己高興就好

TOP

et5323是說少用API函數
請看附檔
GBKEE 發表於 2010-10-7 07:27



    跟版大的方法成功了,但小輩仍在思考...這方式有什麼不好?大大們好像不大建議,是小輩小見,再請大大們教導。

TOP

et5323是說少用API函數
請看附檔
GBKEE 發表於 2010-10-7 07:27



    謝謝版大!先下蛓來學習...

TOP

Sheet1是私用程序,要修改那些?謝謝版大!
大大是說沒有API就不行?
cdkee 發表於 2010-10-6 22:21

et5323是說少用API函數
請看附檔


OnKey.rar (37.07 KB)

TOP

1. In design mode, select your CommandButton1;
2. In the Properties window, enter a single letter for the field Accelerator;

Suppose the caption of your CommandButton1 is “Fire” and a letter “r” is typed in step 2, then letter “r” will be underlined.
Other letters will be accepted but the underline will not shown in the caption.
Also note that it is different for lower and upper case letters.

To run your subroutine, press ALT+r or click CommandButton1 for the above example.
找到像樣的,但要按2個KEY,及FUNCTION KEY不能利用!
請教大大怎樣改,也可會做到?

TOP

回復  cdkee
Sub Ex()
Application.OnKey "{F1}", "Sheet1.CommandButton1_Click"
End Sub

Private  ...
GBKEE 發表於 2010-10-6 21:15



    Sheet1是私用程序,要修改那些?謝謝版大!
這要用API的Hook(鉤子函數)來監視你的鍵盤操作,比較麻煩,很多木馬就使用了這個技術來得到你輸入的密碼、帳 ...
et5323 發表於 2010-10-6 21:26

大大是說沒有API就不行?

TOP

這要用API的Hook(鉤子函數)來監視你的鍵盤操作,比較麻煩,很多木馬就使用了這個技術來得到你輸入的密碼、帳號等資訊。
你在錄製巨集時,會允許你設置一個“快捷鍵”,通過這個快捷鍵來運行宏代碼,也可以得到同樣的目的。

TOP

回復 6# cdkee
Sub Ex()
Application.OnKey "{F1}", "Sheet1.CommandButton1_Click"
End Sub

Private Sub CommandButton1_Click()  -> 是Sheet1 的私用程序嗎?  <- Sheet1 要修改嗎?

TOP

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