.OnKey宏链接

时间:2016-11-29 20:18:14

标签: vba macros

这是我的代码。除了Sorter之外,按下各自的键时,所有宏都可以工作。不确定为什么Handler在按下键时没有调用宏。有什么想法吗?

Public Sub Workbook_Open()
Application.OnKey "^%{~}", "DailyStatusSorter"
End Sub

Public Sub DailyStatusSorter()
' DailyStatusSorter Macro
' Sorts Daily Staus buy completed, priority , then date from oldest to newest.
ActiveWorkbook.Worksheets("Sheet1").ListObjects("Daily_Status").Sort.SortFields _
    .Clear
ActiveWorkbook.Worksheets("Sheet1").ListObjects("Daily_Status").Sort.SortFields _
    .Add Key:=Range("Daily_Status[Last edited by]"), SortOn:=xlSortOnCellColor _
    , Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet1").ListObjects("Daily_Status").Sort.SortFields _
    .Add Key:=Range("Daily_Status[Priority]"), SortOn:=xlSortOnValues, Order _
    :=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet1").ListObjects("Daily_Status").Sort.SortFields _
    .Add Key:=Range("Daily_Status[Date]"), SortOn:=xlSortOnValues, Order:= _
    xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").ListObjects("Daily_Status").Sort
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
End With
End Sub

1 个答案:

答案 0 :(得分:0)

如果您想要Ctrl + Alt + Enter组合,请从密钥中删除{}

Application.OnKey "^%~", "DailyStatusSorter"

如果您保留"^%{~}",则需要按Ctrl + Alt + Shift + ~

p.s。:将宏移动到独立的代码模块,而不是工作簿的代码模块