VBA事件触发器复制? [英] VBA event trigger on copy?
问题描述
或者任何解决方法?
在VBA中有一种方法,在excel中我复制单元格的值会触发我的功能? >或者我可以读取按键和听Ctrl + C吗?
或者可以VBA读取复制的文本的内容?
原因是:我将一些条目从Excel表复制到另一个程序,我想自动添加例如灰色字体颜色到所有条目已经复制。
为您的宏指定一个快捷键。例如,如果您的宏是这样的:
Sub CopyAndMarkAsCopied ()
Dim r As Range
设置r =选择
带r
.Copy
.Font.Color = RGB(100,100,100)'深灰色font
.Interior.Color = RGB(200,200,200)'浅灰色背景
'无论如何
结束
End Sub
在Excel 2010中,在开发人员>宏(或键盘快捷键 Alt - F8 )。在早期版本的Excel中,菜单有所不同,但键盘快捷键的工作原理相同。
在列表中选择您的宏,然后单击选项... 。在此对话框中,您可以为宏指定快捷键。它可以是:
- Ctrl - 一些字母,在这种情况下必须输入一个小写字母;或
- Shift - Ctrl - 一些字母;键入大写字母。
在本例中,我选择了 Ctrl - Shift - C (请注意下面截图中的大写 C
)。
我可能不会屏蔽我通常使用的默认键盘快捷键,如 Ctrl - C ,但是如果这是你的话,可以自由地这样做。
按 Ctrl - Shift - C :
Is there a method in VBA, where when in excel I copy a cell's value it triggers my function?
Or any work-arounds for that?
Or can I read key-downs and listen to Ctrl+C ?
Or can VBA read the content of copied text?
The reason is: I copy some entries from an Excel sheet to another program, and i would like to add automatically for example a gray font color to all entries which are already copied.
Assign a shortcut key to your macro.
For example, if your macro is this:
Sub CopyAndMarkAsCopied()
Dim r As Range
Set r = Selection
With r
.Copy
.Font.Color = RGB(100, 100, 100) 'dark grey font
.Interior.Color = RGB(200, 200, 200) 'light gray background
'whatever else
End With
End Sub
In Excel 2010, view macros in Developer > Macros (or keyboard shortcut Alt-F8). In earlier versions of Excel, the menus are a bit different, but the keyboard shortcut works the same.
Select your macro in the list, and click Options.... In this dialog, you can assign a shortcut key to your macro. It can either be:
- Ctrl-some letter, in which case you have to type a lowercase letter; or
- Shift-Ctrl-some letter; type an uppercase letter.
In this example I chose Ctrl-Shift-C (note the uppercase C
in the screenshot below).
I probably wouldn't mask default keyboard shortcuts that I normally use, like Ctrl-C, but you're free to do so if that's your thing.
Example in action when pressing Ctrl-Shift-C:
这篇关于VBA事件触发器复制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!