PDA

View Full Version : How to figure out which key was pressed?



bobk544
12-11-2007, 05:45 AM
Hello, is there an object or method that i can use in the following macro where i would be able to determine which key was selected?

I'm calling the macro based on the selection of "cntl-alt-p" & "cntl-alt-r" but need to be able to determine which key was actually pressed, ie "p" or "r".

Thanks very much for any ideas!
bk


Sub save_highlight(ht As String, nam As String, bm As String)
'MsgBox (ht + " " + nam + " " + bm)
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Set wrdApp = CreateObject("Word.Application")
Set wrdDoc = wrdApp.Documents.Open("C:\_XREF_PGMS\xref_notes.doc")

Dim sdir As String
sdir = "c:\_XREF_PGMS\" + nam

With wrdDoc
Dim r As Range
Dim l As Integer
Set r = wrdDoc.Range()
.Content.InsertAfter ht
Set r = .Range.Sentences.Last
.Content.Hyperlinks.Add Anchor:=r.Words(1), _
Address:=sdir, SubAddress:=bm
.SaveAs ("C:\_XREF_PGMS\xref_notes.doc")
.Close
End With

wrdApp.Quit
Set wrdDoc = Nothing
Set wrdApp = Nothing
End Sub

TonyJollans
12-11-2007, 07:13 AM
I don't think there's any easy way to do this, but could you perhaps set up separate driving routines something like:


Sub InvokedByP() ' assigned to Ctrl+Alt+P
Call YourRoutine("P")
End Sub
Sub InvokedByR() ' assigned to Ctrl+Alt+R
Call YourRoutine("R")
End Sub
Sub YourRoutine(Caller As String)
' Do whatever you did before
' And use variable Caller when needed
End Sub


As I write this, I see that your routine needs parameters. How are you supplying those when invoked by hotkey combinations?

bobk544
12-11-2007, 07:38 AM
Great idea Tony thanks a bunch!:yes

Have a great week!

BobK