VBA KeyBindings.Add KeyCode not working with f9 but OK with f5- to

P

Peter

My question is. Why can't I use F9 to generate an event while I can use F5,
F6, F7 and F8

The code i am using is:
Sub autoopen()
' so the user only has to click once on the macro field
Options.ButtonFieldClicks = 1
'define f5-f6-f7 to allow them to run the macros
Application.CustomizationContext = ThisDocument
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyF9),
KeyCategory:=wdKeyCategoryCommand, Command:="RubricHelp"
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyF6),
KeyCategory:=wdKeyCategoryCommand, Command:="toggleStandard"
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyF5),
KeyCategory:=wdKeyCategoryCommand, Command:="decrement"
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyF7),
KeyCategory:=wdKeyCategoryCommand, Command:="increment"
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyF8),
KeyCategory:=wdKeyCategoryCommand, Command:="addRescale"
End Sub

Any assistance gratefully received ...

The background is:

I have a small application for an automatic marking rubric that uses VBA to
allow function keys to highlight standards, add and resale marks. It uses VBA
and I want ti to work on Word for windows and Word 2004 for Mac.

I've sorted out most of the issues eg.

* use function keys rather than buttons on a userform to initiate procedures

* use macrofield hyperlink in the document rather than activex button to
iniate a prcedure

* don't use things that are not supprted on VBA mac e.g. INSTRREV or ROUND

* make sure that platform specific code is in seperate procedures even if it
is cloaked with If statements

The applicaiton is at
http://www.usq.edu.au/users/evansp/browse\eMarking_Assistant/Marking_Rubric_dev.doc
and part of the crossplatform code is below
Below is an exmaple of the cross platform code:

Public Sub ShowMarkingRubricToolbar()
If System.OperatingSystem = "Macintosh" Then
showMarkingRubricFunctionKeysMac
Else
ShowMarkingRubricToolbarWin
End If
End Sub

Sub showMarkingRubricFunctionKeysMac()
' show a message box if Macintosh
Dim themessage As String
Dim btns As String
Dim prompt As String
Dim result As String
Dim title As String
title = "You are using a Macintosh computer"
themessage = "Sorry. The toolbar can't be displayed in Word for the
Macintosh." & vbCrLf
themessage = themessage & vbCrLf
themessage = themessage & "But you can use fuction keys to operate
the marking rubric by placing your cursor in the" & vbCrLf
themessage = themessage & "row for the relevant standard and then
pressing the following function keys:" & vbCrLf
themessage = themessage & " F1 - to to the support web site" &
vbCrLf
themessage = themessage & " F5 - decrease the mark by 10%" & vbCrLf
themessage = themessage & " F6 - Select or unselect the standard"
& vbCrLf
themessage = themessage & " F7 - increase the mark by 10%" & vbCrLf
themessage = themessage & " F8 - Add and rescale the marks" & vbCrLf
btns = vbOKOnly
result = MsgBox(themessage, btns, title)
End Sub

Sub ShowMarkingRubricToolbarWin()
'show the marking rubric toolbar if using Windows
Dim UFrm As MarkingRubric
Set UFrm = New MarkingRubric
With UFrm
.Show vbModeless
End With
End Sub
 
J

John McGhie

Hi Peter:

Try this:

Sub KeyBind()
' so the user only has to click once on the macro field
Options.ButtonFieldClicks = 1
'define f5-f6-f7 to allow them to run the macros
Application.CustomizationContext = ThisDocument
With Application.KeyBindings
.Add KeyCode:=BuildKeyCode(wdKeyF9), _
KeyCategory:=wdKeyCategoryCommand, Command:="RubricHelp"
.Add KeyCode:=BuildKeyCode(wdKeyF6), _
KeyCategory:=wdKeyCategoryCommand, Command:="toggleStandard"
.Add KeyCode:=BuildKeyCode(wdKeyF5), _
KeyCategory:=wdKeyCategoryCommand, Command:="decrement"
.Add KeyCode:=BuildKeyCode(wdKeyF7), _
KeyCategory:=wdKeyCategoryCommand, Command:="increment"
.Add KeyCode:=BuildKeyCode(wdKeyF8), _
KeyCategory:=wdKeyCategoryCommand, Command:="addRescale"
End With

End Sub


You need a continuation operator (space + underscore) at the break in each
statement, and you need the "Application" qualifier: Keybindings can be
stored in the document but they are members of the Application context.

You'll forgive me if I don't run this, I don't particularly want to munge my
keybindings :)

Cheers

My question is. Why can't I use F9 to generate an event while I can use F5,
F6, F7 and F8

The code i am using is:
Sub autoopen()
' so the user only has to click once on the macro field
Options.ButtonFieldClicks = 1
'define f5-f6-f7 to allow them to run the macros
Application.CustomizationContext = ThisDocument
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyF9),
KeyCategory:=wdKeyCategoryCommand, Command:="RubricHelp"
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyF6),
KeyCategory:=wdKeyCategoryCommand, Command:="toggleStandard"
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyF5),
KeyCategory:=wdKeyCategoryCommand, Command:="decrement"
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyF7),
KeyCategory:=wdKeyCategoryCommand, Command:="increment"
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyF8),
KeyCategory:=wdKeyCategoryCommand, Command:="addRescale"
End Sub

Any assistance gratefully received ...

The background is:

I have a small application for an automatic marking rubric that uses VBA to
allow function keys to highlight standards, add and resale marks. It uses VBA
and I want ti to work on Word for windows and Word 2004 for Mac.

I've sorted out most of the issues eg.

* use function keys rather than buttons on a userform to initiate procedures

* use macrofield hyperlink in the document rather than activex button to
iniate a prcedure

* don't use things that are not supprted on VBA mac e.g. INSTRREV or ROUND

* make sure that platform specific code is in seperate procedures even if it
is cloaked with If statements

The applicaiton is at
http://www.usq.edu.au/users/evansp/browse\eMarking_Assistant/Marking_Rubric_de
v.doc
and part of the crossplatform code is below
Below is an exmaple of the cross platform code:

Public Sub ShowMarkingRubricToolbar()
If System.OperatingSystem = "Macintosh" Then
showMarkingRubricFunctionKeysMac
Else
ShowMarkingRubricToolbarWin
End If
End Sub

Sub showMarkingRubricFunctionKeysMac()
' show a message box if Macintosh
Dim themessage As String
Dim btns As String
Dim prompt As String
Dim result As String
Dim title As String
title = "You are using a Macintosh computer"
themessage = "Sorry. The toolbar can't be displayed in Word for the
Macintosh." & vbCrLf
themessage = themessage & vbCrLf
themessage = themessage & "But you can use fuction keys to operate
the marking rubric by placing your cursor in the" & vbCrLf
themessage = themessage & "row for the relevant standard and then
pressing the following function keys:" & vbCrLf
themessage = themessage & " F1 - to to the support web site" &
vbCrLf
themessage = themessage & " F5 - decrease the mark by 10%" & vbCrLf
themessage = themessage & " F6 - Select or unselect the standard"
& vbCrLf
themessage = themessage & " F7 - increase the mark by 10%" & vbCrLf
themessage = themessage & " F8 - Add and rescale the marks" & vbCrLf
btns = vbOKOnly
result = MsgBox(themessage, btns, title)
End Sub

Sub ShowMarkingRubricToolbarWin()
'show the marking rubric toolbar if using Windows
Dim UFrm As MarkingRubric
Set UFrm = New MarkingRubric
With UFrm
.Show vbModeless
End With
End Sub

--
Don't wait for your answer, click here: http://www.word.mvps.org/

Please reply in the group. Please do NOT email me unless I ask you to.

John McGhie, Microsoft MVP, Word and Word:Mac
Sydney, Australia. mailto:[email protected]
 
C

CyberTaz

My guess would be that F9-F12 are used by OS X & assigned to Dashboard &
Exposé. Those assignments take precedence, so if you haven't changed them in
System Preferences any calls to those keys won't execute your assignments.

HTH |:>)
Bob Jones
[MVP] Office:Mac
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top