跳转到谷歌电子表格宏中的特定单元格

时间:2021-06-09 21:53:33

标签: google-apps-script google-sheets spreadsheet

我知道 f5 可以打开跳转到单元格对话框,它的问题在于,虽然它允许您执行一次,但下次按 f5 时,可以跳转到另一个特定单元格,即上一个文本未突出显示,因此您需要将手从键盘上移开并用鼠标选择它。

如果我能有一种方法让我的手不离开键盘,那将极大地加快我的工作流程。

有什么想法吗?

比如,我需要一个宏来弹出转到范围对话框并选择那里的任何文本,以便我可以输入新的单元格范围(例如:a391)

谢谢!

4 个答案:

答案 0 :(得分:1)

有一种向表格添加自定义宏的简单方法。您只需要预先创建一个 bounded script,其中包含一个 function 和您想要的操作。然后您可以按照以下步骤操作:

  1. 转到Tools > Macros > Import
  2. 找到您的函数并点击 Add Function 并点击 X 关闭。
  3. 转到Tools > Macros > Manage Macros
  4. 为您的宏指定一个数字并点击 Update
  5. 使用 Ctrl + Alt + Shift + {NUMBER}
  6. 运行您的宏

按照这些步骤,您将轻松创建自定义宏,但如有任何疑问,请随时问我。

答案 1 :(得分:0)

Google 电子表格中的键盘快捷键相当糟糕。如果您使用的是 Windows,我建议您尝试 Autohotkey。它可以将光标移动到屏幕上的任何坐标(坐标可以设置为相对当前窗口)。例如,'Win+F5' 可以作为 F5 + 移动屏幕右上角的光标并执行左键单击。

答案 2 :(得分:0)

适用于 MacOS(High Sierra,可能也适用于较新的操作系统)

我从这里下载了文件 AppleScript Toolbox.osaxhttps://astoolbox.wordpress.com/

将文件放入文件夹:/Users/me/Library/ScriptingAdditions

运行 Automator 并启动一个新服务:

enter image description here

enter image description here

粘贴此脚本

activate application "Firefox" -- or "Safari" or "Chrome", etc
set mousePointLocation1 to {1700, 250} -- coordinates depend on your screen size
AST click at mousePointLocation1 number of clicks 1

并保存:

enter image description here

转到 Preferences > Keyboard > Services 并为此服务添加快捷方式

enter image description here

之后,您将在此处看到新的快捷方式:

enter image description here

在 Google 电子表格中,我按 F5 以显示面板,然后按 ^F5 并且光标在此面板上跳转并单击。

我是 macOS 的菜鸟,我相信它可以做得更好。这就是我现在设法做到的。

脚本的另一个修改可能更方便:

activate application "Firefox"

tell application "System Events" 
  key code 96 -- this is F5 key
end tell

delay .5

AST click at {1700, 250} number of clicks 2 -- or 3 maybe

这样您就不需要按 F5。只需按 ^F5 并继续。


有效

enter image description here


以防万一。如果你懂 Python。我已经设法按下 F5 移动并点击带有 Python 模块 pynput 的鼠标:

from pynput import mouse, keyboard

k = keyboard.Controller()
k.press(keyboard.Key.f5)
k.release(keyboard.Key.f5)

m = mouse.Controller()
m.position = (1700, 240)
m.press(mouse.Button.left)
m.release(mouse.Button.left)
m.click(mouse.Button.left, 2)

https://pynput.readthedocs.io/en/latest/

可以这样转换成macOS Service:

enter image description here

然后您可以通过 Keyboard > Services > Add Shortcut

以同样的方式运行此服务

答案 3 :(得分:0)

我刚刚找到了另一个更明显的原生解决方案。

将代码放入脚本编辑器:

function jump() {
  var range = SpreadsheetApp.getUi().prompt('Input cell').getResponseText();
  SpreadsheetApp.getActiveSheet().getRange(range).activate();
}

保存并将函数添加为宏:

enter image description here

enter image description here

然后为宏分配一些快捷方式:

enter image description here

enter image description here

之后你可以按下快捷键(CmdOptionShift5 在我的情况下),输入单元格地址,按 TabEnter 就可以了。

enter image description here

相关问题