我希望计算机在excel工作表中的某个单元格(例如A1)的值更改为某个值(例如“ 1”)之后立即自动按下某个组合键(例如Ctrl + Alt + x)。我已经在互联网上搜索了几个小时,但找不到与我的情况完全相同的信息。请帮助,非常感谢。
我敢肯定您不需要输入按键组合,但是如果您确实想输入,请输入SendKeys
。此代码将执行许多操作,具体取决于在单元格A1中输入的值,并使用SendKeys命令完成该操作:
'Fires when you change a value on the sheet.
Private Sub Worksheet_Change(ByVal Target As Range)
'Was only a single cell selected?
If Target.Cells.Count = 1 Then
'Was the value changed (Target) in range A1?
If Not Intersect(Target, Range("A1")) Is Nothing Then
'Perform an action depending on Targets value.
Select Case Target.Value
Case 1
'Cut the Target cell (Ctrl+x).
Target.Cut
Case 2
'Copy the Target cell (Ctrl+c).
Target.Copy
Case 3
'Filldown from the Target 10 rows.
Target.Resize(10).FillDown
Case 4
'Change the font colour to red.
Target.Font.Color = vbRed
Case "Hello"
'Change the contents of the cell.
'This will cause the Change event to fire again, so disable events first.
Application.EnableEvents = False
Target.Value = "Goodbye"
Application.EnableEvents = True
Case Else
'If anything else is press keys Right Arrow, Up Arrow, F2.
SendKeys "{RIGHT}{UP}{F2}"
End Select
End If
End If
End Sub
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句