Using specific keyboard keys in a form macro

Hey all, I’m trying to make it so that a specific keyboard key triggers a button in a form. The macro works well in MSFT office, but it just sets to other random keys in Calc 7.0 (in version 5.something, it doesn’t even work!).
I’ve tried tinkering a bit with the macro, but to no avail. I’m not very good at programming, but I’ve reverse-engineered a previous file and modified it to serve my needs - so not really sure where to put my hand without breaking it! :smiling_face_with_tear:

Any help?

Here is a screen of the form: if you activate macros, and press “inserisci”, you get the item entry form. I want to be able to press keys 1 to 4 to enter the variables (there’s the corresponding number in brackets), but Calc defaults to S, T, V and 4. Tried to change the text labels but not working.
Form LO 7.0
Uploading the file as well, if it can help!
Scoring_1.xls (109 KB)

Thanks

without checking any code I think Calc defaults to the first letters of the words, if not already taken. As 4 seems possible, my first try would be to put the numbers in front like 1 - Sempre/Spesso Falso

You tried with LibreOffice or with MS-Office? What did “not work”? You can not change the labels, or this had no effect?

1 Like

@lucapaschi, your macro uses the KeyPress (VBA) event handler.
MSG code module (VBA):

Private Sub vero_KeyPress(ByVal KeyCode As MSForms.ReturnInteger)

If KeyCode = vbKey1 Then
    Worksheets("PID-5").Cells(riga, col).Value = "0"
    xc = False
    Unload Msg
ElseIf KeyCode = vbKey2 Then
' ...
End If
End Sub

This Excel VBA construct is currently not supported in LibreOffice.

thanks, do you know if there’s an equivalent or does it just assigns them to random/first letter keys?

Yes, when I say labels I mean I tried to change the text on the buttons to have the numbers first.
Basically, what happens is that the buttons that set the macro brigning the form up just disappear from the sheet. Don’t really know why.
I tried again today using LO 7 and it worked, but then saving the file and reopening i would bring me to the same “buttons disappearing” issue. I tried to change the text on Office, and will check if it works any better on monday! :frowning:
Saving as a native LO format, brings a runtime 423 error on the Msg.Show that should bring up the form when the macro starts.

The object models of Excel and Calc are fundamentally different. LibreOffice developers have done a great job of interpreting (emulating) Excel VBA constructs, but, of course, 100% support is not real.
You can help yourself. :slightly_smiling_face:
In Excel adjust the button caption

Sempre/Spesso Falso (1)

to

Sempre/Spesso Falso (~1)

When opening dialog in Calc you will be able to “click” this button using the keyboard shortcut Alt + 1.
Do the same with other buttons.

Thanks! This might be a good enough workaround if the others fail… :wink:

As I avoided writing VBA-macros as much as possible, I’m not very experienced here, but if this only shows from .ods and not when loading from .xls you may need to set vba-compatibility for the module yourself.
.
When loading MS-Office files it depends on general settings, if macros are read/run at all. If they are run, Calc “assumes” they need vba-compatibility, but if loaded from .odc, Calc can’t know and you have to add the line to your code yourself.

Option VBAsupport 1

I learned, you can even test for this or set it by function: CompatibilityMode()
https://help.libreoffice.org/7.6/en-US/text/sbasic/shared/compatibilitymode.html?&DbPAR=SHARED&System=UNIX
.
However this will not help for features not available like the one @sokol92 mentioned.

Thanks! Will give it try if the simple renaming the button still doesn’t work!