gpt4 book ai didi

vba - 将功能键分配给 excel 宏

转载 作者:行者123 更新时间:2023-12-04 22:49:55 25 4
gpt4 key购买 nike

我已经看到以下示例代码建议将功能键分配给 excel 宏,但无论我在哪里尝试复制代码(模块、工作簿、工作表),总的来说,始终执行原始分配的功能键任务而不是尝试/分配的宏。此代码是否需要某种类型的高级代码才能首先禁用功能键的原始分配任务?

Sub A_1()
Call sndPlaySound32(ThisWorkbook.Path & "\a1.wav", 0)
End Sub

Sub B_1()
Call sndPlaySound32(ThisWorkbook.Path & "\b1.wav", 0)
End Sub

Sub C_1()
Call sndPlaySound32(ThisWorkbook.Path & "\c1.wav", 0)
End Sub

Sub D_1()
Call sndPlaySound32(ThisWorkbook.Path & "\d1.wav", 0)
End Sub

Sub E_1()
Call sndPlaySound32(ThisWorkbook.Path & "\e1.wav", 0)
End Sub


Sub auto_open()
Application.OnKey "{F1}", "A_1"
Application.OnKey "{F2}", "B_1"
Application.OnKey "{F3}", "C_1"
Application.OnKey "{F4}", "D_1"
Application.OnKey "{F5}", "E_1"
End Sub

最佳答案

将其放在工作簿代码区域:

Private Sub Workbook_Open()
Application.OnKey "{F1}", "A_1"
Application.OnKey "{F2}", "B_1"
Application.OnKey "{F3}", "C_1"
Application.OnKey "{F4}", "D_1"
Application.OnKey "{F5}", "E_1"
End Sub

将您的其他潜艇放在标准模块中。

OnKey 分配将在工作簿打开时发生。要恢复正常的功能键行为,请运行:

Sub reset()
Application.OnKey "{F1}"
Application.OnKey "{F2}"
Application.OnKey "{F3}"
Application.OnKey "{F4}"
Application.OnKey "{F5}"
End Sub

关于vba - 将功能键分配给 excel 宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50052786/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com