Excel公式栏能否实现VSCode中Ctrl+Shift+L的全选高亮文本功能?
Excel公式栏实现批量选中相同文本的方法
Excel公式栏没有直接对应VSCode中Ctrl+Shift+L的原生快捷键,但可以通过以下两种方式实现类似功能:
原生操作步骤
- 在公式栏中选中你要批量匹配的文本
- 按下
Ctrl+Shift+F打开查找对话框 - 点击对话框中的查找全部按钮,此时对话框底部会列出所有匹配结果
- 按下
Ctrl+A选中列表里的所有结果,公式栏中对应的所有相同文本会被同时选中
自定义快捷键(VBA宏方案)
如果需要更接近VSCode的一键操作体验,可以编写VBA宏并绑定快捷键:
- 按下
Alt+F11打开VBA编辑器 - 插入新模块,粘贴以下代码:
Sub SelectAllOccurrences() Dim searchText As String Dim formulaBarEdit As Object ' 获取公式栏的编辑控件 Set formulaBarEdit = Application.CommandBars("Formula Bar").FindControl(Type:=msoControlEdit) If formulaBarEdit Is Nothing Then Exit Sub ' 获取当前选中的文本 searchText = formulaBarEdit.SelText If searchText = "" Then Exit Sub formulaBarEdit.SetFocus Dim currentPos As Long currentPos = 1 ' 循环查找并选中所有匹配项 Do While currentPos <= Len(formulaBarEdit.Text) currentPos = InStr(currentPos, formulaBarEdit.Text, searchText, vbTextCompare) If currentPos = 0 Then Exit Do formulaBarEdit.SelStart = currentPos - 1 formulaBarEdit.SelLength = Len(searchText) ' 保持多选中状态(模拟按住Ctrl) SendKeys "^+" currentPos = currentPos + Len(searchText) Loop End Sub
- 返回Excel,按下
Alt+F8打开宏对话框,选中SelectAllOccurrences宏,点击选项设置快捷键(比如Ctrl+Shift+L)
注意
- 使用VBA宏需要启用Excel的宏功能
- 若要在所有工作簿中使用该功能,可将宏保存为Excel加载项
内容的提问来源于stack exchange,提问作者HenriDev
相关产品推荐
相关产品推荐

