Change default F12

D

Dimitris

Hello there,

is it possible to change the F12 button from "Save As" and when the user
press it to be equal as he had press "Enter" Button?
Also I would like to know if I can change the built-in shortcut for the
"Save As" from F2 to something else.

thanks

Dimitris
 
P

Peter T

You can assign F12 to some other macro that does nothing, see OnKey in help.
But unless you need F12 for other purposes what harm is it doing.

What's wrong with Ctrl-s as a built-in alternative to F12, or Alt-f, a.

Regards,
Peter T
 
D

Dimitris

With this line can I call Enter when I press F12 : Application.OnKey
"{F12}", "{ENTER}"

It is not working to me and I have the message:"I can not Find the macro
ENTER.

Thanks

Dimitris
 
P

Peter T

Sub test()
OnKeyEdit 1 ' 0 to reset to default
End Sub

Sub OnKeyEdit(SetType As Long)
Dim sMacro As String
If SetType = 0 Then
' reset default
Application.OnKey "{F12}"
Else
If SetType = 1 Then
sMacro = "EditCell"
Else
' some other number to send an empty string
' and clear F12 of any action, even default
End If
Application.OnKey "{F12}", sMacro
End If

End Sub

Sub EditCell()
Application.SendKeys ("{F2}")
End Sub


Regards,
Peter T
 
D

Dimitris

Thanks a lot Peter

Dimitris

Peter T said:
Sub test()
OnKeyEdit 1 ' 0 to reset to default
End Sub

Sub OnKeyEdit(SetType As Long)
Dim sMacro As String
If SetType = 0 Then
' reset default
Application.OnKey "{F12}"
Else
If SetType = 1 Then
sMacro = "EditCell"
Else
' some other number to send an empty string
' and clear F12 of any action, even default
End If
Application.OnKey "{F12}", sMacro
End If

End Sub

Sub EditCell()
Application.SendKeys ("{F2}")
End Sub


Regards,
Peter T
 
D

Dimitris

Good afternoon from Greece

One more last question. If you are in a cell in edit mode and press F12
excel ignore the previous code and the F12 is again Save as.... How can i
Pass this problem? If you are not in the cell but you have just select it,
the code work perfect

Thanks...
 
P

Peter T

Yes I see what you mean.

Normally when in edit mode all code is suspended. Besides F12 I'm also
surprised to see F1 and F7 appear to work. I don't know how to avoid that
and suspect it's not possible, at least not with normal VBA methods.

Look again at the code I posted and notice how if you pass say '2' to the
OnKeyEdit routine it disables F12 as a SaveAs shortcut (as intended).
However if you enter edit mode then press F12, it will call the SaveAs
dialog. Exit edit mode and the F12 key reverts to being disabled. I have
never noticed that behaviour before.

Regards,
Peter T
 
D

Dimitris

The problem that I have to deal with is that I will pass values from a
barcode reader. The reader have a predifed suffix that it is F12 and i must
not change it. With the code (not in edit mode in a cell) everything works
perfect. But in my case the barcode pass the data in edit mode in the cell
and so I can not bypass the F12.

And this is a big problem for me.

Thanks anyway Peter. If you found something I would be very happy to hear it.

Dimitris
 

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