ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Can VBA hook onto function keys??? (https://www.excelbanter.com/excel-programming/435579-can-vba-hook-onto-function-keys.html)

Robert Crandal

Can VBA hook onto function keys???
 
Suppose I have a string value in Cell A1..... Can I somehow
associate the data in cell A1 with the F1 function key???

Ideally, I would like to be able to switch to other applications
and just use the function keys to grab data out of Excel
and paste the data into other apps using just the function keys.

Thank you everyone for all your tips!

Robert


smartin

Can VBA hook onto function keys???
 
Robert Crandal wrote:
Suppose I have a string value in Cell A1..... Can I somehow
associate the data in cell A1 with the F1 function key???

Ideally, I would like to be able to switch to other applications
and just use the function keys to grab data out of Excel
and paste the data into other apps using just the function keys.

Thank you everyone for all your tips!

Robert


Yes and no. You can trap the F1 key to do whatever you like /in Excel/
but other applications will do whatever F1 does there.

To your point though, you could do something like this.

In a workbook's ThisWorkbook module, place:

Private Sub Workbook_Activate()
Application.OnKey "{F1}", "CopyValueToClipboard"
End Sub


And in a standard module place (*)

Sub CopyValueToClipboard()
Dim DataObj As New MSForms.Dataobject
DataObj.SetText ActiveSheet.Range("A1").Value
DataObj.PutInClipboard
End Sub


The first procedure tells Excel to fire "CopyValueToClipboard" when F1
is pressed (pressed within Excel that is).

The second procedure places the value from A1 on the clipboard. You can
now switch to another application and paste.

(*) as seen on Chip Pearson's site:
http://www.cpearson.com/excel/Clipboard.aspx


All times are GMT +1. The time now is 07:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com