diff --git a/src/functions/Cell.bas b/src/functions/Cell.bas index db320d4..9d2e524 100644 --- a/src/functions/Cell.bas +++ b/src/functions/Cell.bas @@ -175,22 +175,22 @@ End Function Function YankFromUpCell(Optional ByVal g As String) As Boolean Call RepeatRegister("YankFromUpCell") - Call KeyStroke(Alt_, H_, F_, I_, D_) + Selection.FillDown End Function Function YankFromDownCell(Optional ByVal g As String) As Boolean Call RepeatRegister("YankFromDownCell") - Call KeyStroke(Alt_, H_, F_, I_, U_) + Selection.FillUp End Function Function YankFromLeftCell(Optional ByVal g As String) As Boolean Call RepeatRegister("YankFromLeftCell") - Call KeyStroke(Alt_, H_, F_, I_, R_) + Selection.FillRight End Function Function YankFromRightCell(Optional ByVal g As String) As Boolean Call RepeatRegister("YankFromRightCell") - Call KeyStroke(Alt_, H_, F_, I_, L_) + Selection.FillLeft End Function Function YankAsPlaintext(Optional ByVal ColumnSpliter As String = vbTab) As Boolean @@ -411,7 +411,7 @@ Function IncrementText(Optional ByVal g As String) As Boolean Dim i As Integer For i = 1 To gVim.Count1 - Call KeyStroke(Alt_, H_, k6_) + Application.CommandBars.ExecuteMso "IndentIncrease" Next i End Function @@ -422,7 +422,7 @@ Function DecrementText(Optional ByVal g As String) As Boolean Dim i As Integer For i = 1 To gVim.Count1 - Call KeyStroke(Alt_, H_, k5_) + Application.CommandBars.ExecuteMso "IndentDecrease" Next i End Function @@ -433,7 +433,7 @@ Function IncreaseDecimal(Optional ByVal g As String) As Boolean Dim i As Integer For i = 1 To gVim.Count1 - Call KeyStroke(Alt_, H_, k0_) + Application.CommandBars.ExecuteMso "DecimalsIncrease" Next i End Function @@ -444,7 +444,7 @@ Function DecreaseDecimal(Optional ByVal g As String) As Boolean Dim i As Integer For i = 1 To gVim.Count1 - Call KeyStroke(Alt_, H_, k9_) + Application.CommandBars.ExecuteMso "DecimalsDecrease" Next i End Function @@ -741,7 +741,9 @@ End Function Function ToggleWrapText(Optional ByVal g As String) As Boolean Call StopVisualMode - Call KeyStroke(Alt_, H_, W_) + If TypeName(Selection) = "Range" Then + Selection.WrapText = Not Selection.WrapText + End If End Function Function ToggleMergeCells(Optional ByVal g As String) As Boolean @@ -754,9 +756,9 @@ Function ToggleMergeCells(Optional ByVal g As String) As Boolean End If If ActiveCell.MergeCells Then - Call KeyStroke(Alt_, H_, M_, U_) + Selection.UnMerge Else - Call KeyStroke(Alt_, H_, M_, M_) + Application.CommandBars.ExecuteMso "MergeCenter" End If End If End Function @@ -765,7 +767,7 @@ Function ApplyCommaStyle(Optional ByVal g As String) As Boolean Call RepeatRegister("ApplyCommaStyle") Call StopVisualMode - Call KeyStroke(Alt_, H_, K_) + Application.CommandBars.ExecuteMso "CommaStyle" End Function Function ChangeInteriorColor(Optional ByVal resultColor As cls_FontColor) As Boolean @@ -1154,14 +1156,14 @@ Function ShowCellPicker(Optional ByVal g As String) As Boolean Call UF_Picker.Launch(New cls_CellPicker) End Function -Private Function AutoSumInner(ByVal lastKey As Long) +Private Function AutoSumInner(ByVal msoId As String) On Error GoTo Catch If TypeName(Selection) <> "Range" Then Exit Function End If - Call KeyStroke(Alt_, M_, U_, lastKey) + Application.CommandBars.ExecuteMso msoId Exit Function Catch: @@ -1169,23 +1171,23 @@ Catch: End Function Function AutoSum(Optional ByVal g As String) As Boolean - Call AutoSumInner(S_) + Call AutoSumInner("AutoSum") End Function Function AutoAverage(Optional ByVal g As String) As Boolean - Call AutoSumInner(A_) + Call AutoSumInner("AutoSumAverage") End Function Function AutoCount(Optional ByVal g As String) As Boolean - Call AutoSumInner(C_) + Call AutoSumInner("AutoSumCount") End Function Function AutoMax(Optional ByVal g As String) As Boolean - Call AutoSumInner(M_) + Call AutoSumInner("AutoSumMax") End Function Function AutoMin(Optional ByVal g As String) As Boolean - Call AutoSumInner(I_) + Call AutoSumInner("AutoSumMin") End Function Function InsertFunction(Optional ByVal g As String) As Boolean diff --git a/src/functions/Column.bas b/src/functions/Column.bas index 39cb392..ee9edd0 100644 --- a/src/functions/Column.bas +++ b/src/functions/Column.bas @@ -169,7 +169,7 @@ Function InsertColumns(Optional ByVal g As String) As Boolean Target.Select savedCell.Activate - Call KeyStroke(Alt_, I_, C_) + Selection.EntireColumn.Insert Shift:=xlToRight Catch: Application.ScreenUpdating = True @@ -202,7 +202,7 @@ Function AppendColumns(Optional ByVal g As String) As Boolean Target.Select savedCell.Activate - Call KeyStroke(Alt_, I_, C_) + Selection.EntireColumn.Insert Shift:=xlToRight Catch: Application.ScreenUpdating = True @@ -298,7 +298,7 @@ Function UnhideColumns(Optional ByVal g As String) As Boolean 'ref: https://excel.nj-clucker.com/ctrl-shift-0-not-working/ 'Call KeyStroke(Ctrl_ + Shift_ + k0_) - Call KeyStroke(Alt_, H_, O_, U_, L_) + Selection.EntireColumn.Hidden = False Exit Function Catch: @@ -393,7 +393,7 @@ Function AdjustColumnsWidth(Optional ByVal g As String) As Boolean Selection.Resize(Selection.Rows.Count, gVim.Count1).Select End If - Call KeyStroke(Alt_, H_, O_, I_) + Selection.EntireColumn.AutoFit Exit Function Catch: @@ -409,7 +409,7 @@ Function SetColumnsWidth(Optional ByVal g As String) As Boolean Selection.Resize(Selection.Rows.Count, gVim.Count1).Select End If - Call KeyStroke(Alt_, H_, O_, W_) + Application.Dialogs(xlDialogColumnWidth).Show Exit Function Catch: diff --git a/src/functions/Filter.bas b/src/functions/Filter.bas index 2536f38..6a70784 100644 --- a/src/functions/Filter.bas +++ b/src/functions/Filter.bas @@ -99,18 +99,27 @@ Function ToggleAutoFilter(Optional ByVal g As String) As Boolean If Not lo Is Nothing Then ' Table context - Call KeyStroke(Alt_ + J_, T_, B_) + lo.ShowAutoFilterDropDown = Not lo.ShowAutoFilterDropDown If lo.ShowAutoFilterDropDown Then - Call SetStatusBarTemporarily(gVim.Msg.AutoFilterOff, 2000) - Else Call SetStatusBarTemporarily(gVim.Msg.AutoFilterOn, 2000) + Else + Call SetStatusBarTemporarily(gVim.Msg.AutoFilterOff, 2000) End If Else ' Worksheet context - Call KeyStroke(Alt_ + A_, T_) + Dim wasOn As Boolean + wasOn = ws.AutoFilterMode - If ws.AutoFilterMode Then + If wasOn Then + ws.AutoFilterMode = False + Else + If ws.UsedRange.Count > 0 Then + ws.UsedRange.AutoFilter + End If + End If + + If wasOn Then Call SetStatusBarTemporarily(gVim.Msg.AutoFilterOff, 2000) Else Call SetStatusBarTemporarily(gVim.Msg.AutoFilterOn, 2000) @@ -145,17 +154,16 @@ Function ClearAllFilters(Optional ByVal g As String) As Boolean If Not lo Is Nothing Then If lo.ShowAutoFilter Then - ' Check if any filter is applied If Not lo.AutoFilter Is Nothing Then If lo.AutoFilter.FilterMode Then - Call KeyStroke(Alt_ + A_, C_) + lo.AutoFilter.ShowAllData cleared = True End If End If End If Else If ws.FilterMode Then - Call KeyStroke(Alt_ + A_, C_) + ws.ShowAllData cleared = True End If End If @@ -255,9 +263,9 @@ Private Function ApplyAutoFilter(ByVal Field As Long, ByVal Criteria1 As Variant Set ws = ActiveSheet If Not IsAutoFilterOn(ws) Then - ' If AutoFilter is not active, apply it to the current region. - ' This assumes the active cell is within the data range. - Call KeyStroke(Alt_ + A_, T_) + If ws.UsedRange.Count > 0 Then + ws.UsedRange.AutoFilter + End If Call SetStatusBarTemporarily(gVim.Msg.AutoFilterOn, 2000) End If diff --git a/src/functions/Find_Replace.bas b/src/functions/Find_Replace.bas index eef28e2..56e7011 100644 --- a/src/functions/Find_Replace.bas +++ b/src/functions/Find_Replace.bas @@ -106,7 +106,7 @@ Catch: End Function Function ShowReplaceWindow(Optional ByVal g As String) As Boolean - Call KeyStroke(Alt_, E_, E_) + Application.CommandBars.ExecuteMso "ReplaceDialog" End Function Function FindActiveValueNext(Optional ByVal g As String) As Boolean diff --git a/src/functions/Font.bas b/src/functions/Font.bas index a737e29..d4d5e74 100644 --- a/src/functions/Font.bas +++ b/src/functions/Font.bas @@ -8,7 +8,7 @@ Function IncreaseFontSize(Optional ByVal g As String) As Boolean Dim i As Long For i = 1 To gVim.Count1 - Call KeyStroke(Alt_, H_, F_, G_) + Application.CommandBars.ExecuteMso "GrowFont" Next i End Function @@ -18,7 +18,7 @@ Function DecreaseFontSize(Optional ByVal g As String) As Boolean Dim i As Long For i = 1 To gVim.Count1 - Call KeyStroke(Alt_, H_, F_, K_) + Application.CommandBars.ExecuteMso "ShrinkFont" Next i End Function @@ -33,65 +33,37 @@ End Function Function AlignLeft(Optional ByVal g As String) As Boolean Call RepeatRegister("AlignLeft") Call StopVisualMode - - 'Check excel version - On Error GoTo Excel2019 - If CDbl(Application.Version) >= 16 Then - 'Raise error in Excel 2016, 2019 (Sequence exists in Excel 2021 and later) - WorksheetFunction.Sequence 1 - End If - - 'Default - Call KeyStroke(Alt_, H_, A_, L_) - Exit Function - -Excel2019: - 'Excel 2019 and earlier - Call KeyStroke(Alt_, H_, L_, k1_) + Selection.HorizontalAlignment = xlLeft End Function Function AlignCenter(Optional ByVal g As String) As Boolean Call RepeatRegister("AlignCenter") Call StopVisualMode - Call KeyStroke(Alt_, H_, A_, C_) + Selection.HorizontalAlignment = xlCenter End Function Function AlignRight(Optional ByVal g As String) As Boolean Call RepeatRegister("AlignRight") Call StopVisualMode - - 'Check excel version - On Error GoTo Excel2019 - If CDbl(Application.Version) >= 16 Then - 'Raise error in Excel 2016, 2019 (Sequence exists in Excel 2021 and later) - WorksheetFunction.Sequence 1 - End If - - 'Default - Call KeyStroke(Alt_, H_, A_, R_) - Exit Function - -Excel2019: - 'Excel 2019 and earlier - Call KeyStroke(Alt_, H_, R_) + Selection.HorizontalAlignment = xlRight End Function Function AlignTop(Optional ByVal g As String) As Boolean Call RepeatRegister("AlignTop") Call StopVisualMode - Call KeyStroke(Alt_, H_, A_, T_) + Selection.VerticalAlignment = xlTop End Function Function AlignMiddle(Optional ByVal g As String) As Boolean Call RepeatRegister("AlignMiddle") Call StopVisualMode - Call KeyStroke(Alt_, H_, A_, M_) + Selection.VerticalAlignment = xlCenter End Function Function AlignBottom(Optional ByVal g As String) As Boolean Call RepeatRegister("AlignBottom") Call StopVisualMode - Call KeyStroke(Alt_, H_, A_, B_) + Selection.VerticalAlignment = xlBottom End Function Function ToggleBold(Optional ByVal g As String) As Boolean @@ -119,7 +91,7 @@ Function ToggleStrikethrough(Optional ByVal g As String) As Boolean End Function Function ChangeFormat(Optional ByVal g As String) As Boolean - Call KeyStroke(Alt_, H_, N_, Down_, Down_) + Application.CommandBars.ExecuteMso "NumberFormatsDialog" End Function Function showFontDialog(Optional ByVal g As String) As Boolean diff --git a/src/functions/Paste.bas b/src/functions/Paste.bas index b50e235..6664df8 100644 --- a/src/functions/Paste.bas +++ b/src/functions/Paste.bas @@ -109,17 +109,17 @@ Function PasteValue(Optional ByVal g As String) As Boolean End If cbType = cb(2) - If Application.CutCopyMode > 0 Then 'Cells - Call KeyStroke(Alt_, H_, V_, V_) + If Application.CutCopyMode > 0 Then + Selection.PasteSpecial Paste:=xlPasteValues Else Select Case cbType Case xlClipboardFormatText Call KeyStroke(Ctrl_ + V_) Case xlClipboardFormatRTF - Call KeyStroke(Alt_, H_, V_, T_) + Application.CommandBars.ExecuteMso "PasteTextOnly" Case xlHtml - Call KeyStroke(Alt_, H_, V_, S_, End_, Enter_) + Application.CommandBars.ExecuteMso "PasteSpecialDialog" Case Else Call DebugPrint("Unknown ClipboardType: " & cbType, "PasteValue") End Select diff --git a/src/functions/Row.bas b/src/functions/Row.bas index ab90885..4e4eb29 100644 --- a/src/functions/Row.bas +++ b/src/functions/Row.bas @@ -169,7 +169,7 @@ Function InsertRows(Optional ByVal g As String) As Boolean Target.Select savedCell.Activate - Call KeyStroke(Alt_, I_, R_) + Selection.EntireRow.Insert Shift:=xlDown Catch: Application.ScreenUpdating = True @@ -202,7 +202,7 @@ Function AppendRows(Optional ByVal g As String) As Boolean Target.Select savedCell.Activate - Call KeyStroke(Alt_, I_, R_) + Selection.EntireRow.Insert Shift:=xlDown Catch: Application.ScreenUpdating = True @@ -391,7 +391,7 @@ Function AdjustRowsHeight(Optional ByVal g As String) As Boolean Selection.Resize(gVim.Count1, Selection.Columns.Count).Select End If - Call KeyStroke(Alt_, H_, O_, A_) + Selection.EntireRow.AutoFit Exit Function Catch: @@ -407,7 +407,7 @@ Function SetRowsHeight(Optional ByVal g As String) As Boolean Selection.Resize(gVim.Count1, Selection.Columns.Count).Select End If - Call KeyStroke(Alt_, H_, O_, H_) + Application.Dialogs(xlDialogRowHeight).Show Exit Function Catch: diff --git a/src/functions/UsefulCmd.bas b/src/functions/UsefulCmd.bas index 7b4a51c..ee07b08 100644 --- a/src/functions/UsefulCmd.bas +++ b/src/functions/UsefulCmd.bas @@ -174,35 +174,27 @@ End Function Function SetPrintArea(Optional ByVal g As String) As Boolean Call StopVisualMode - - 'Send Alt, P, R, S - Call KeyStroke(Alt_, P_, R_, S_) + Application.CommandBars.ExecuteMso "PrintAreaSet" End Function Function ClearPrintArea(Optional ByVal g As String) As Boolean Call StopVisualMode - - 'Send Alt, P, R, C - Call KeyStroke(Alt_, P_, R_, C_) + Application.CommandBars.ExecuteMso "PrintAreaClear" End Function Function Sort(Optional ByVal sortOrder As XlSortOrder) As Boolean Call StopVisualMode If sortOrder = xlAscending Then - 'Send Alt, A, S, A - Call KeyStroke(Alt_, A_, S_, A_) + Application.CommandBars.ExecuteMso "SortAscendingExcel" Else - 'Send Alt, A, S, D - Call KeyStroke(Alt_, A_, S_, D_) + Application.CommandBars.ExecuteMso "SortDescendingExcel" End If End Function Function RemoveDuplicates(Optional ByVal g As String) As Boolean Call StopVisualMode - - 'Send Alt, A, M, Shift + Tab, Shift + Tab - Call KeyStroke(Alt_, A_, M_, Shift_ + Tab_, Shift_ + Tab_) + Application.CommandBars.ExecuteMso "RemoveDuplicates" End Function Function ShowShapePicker(Optional ByVal g As String) As Boolean