Command line switch -enterkey

Hi,

i try to use a ribbon to enter a new activation key and replace the existing one.

Sub newkey(control As IRibbonControl)
Dim RetVal
RetVal = Shell(PathToFile("myapp.exe  -enterkey"), 2)
Application.Quit
AppActivate ThisWorkbook.Windows(1).Caption
End Sub

my problem is the focus.
i want to close myapp and have the focus on the register program.
is this possible?
Thanks.

What is already happening when you run the code above?

Hi,

the registration process opens in the background, because of the 2 ( vbMinimizedFocus).
with vbNormalFocus (1) the registration process opens in front of my messagebox to close myapp.

i want to close/save (own routine with msgbox) myapp.exe before the registration process begins. Otherwise it may happen that the application is opened twice

Maybe you could delay the closing of the workbook with a timer event?
https://docs.microsoft.com/en-us/office/vba/api/excel.application.ontime
Something like this:

Sub newkey(control As IRibbonControl)
Dim RetVal
RetVal = Shell(PathToFile("myapp.exe  -enterkey"), 2)
Application.OnTime Now + TimeValue("00:00:05"), "my_closing"
AppActivate ThisWorkbook.Windows(1).Caption
End Sub

And the procedure my_closing would close the workbook.

but i want to close the workbook first. or can I prevent with the command line that myapp after the registration starts?

my solution.

Public withoutcancel As Boolean
Sub register(control As IRibbonControl)
withoutcancel = True
Application.Quit
AppActivate ThisWorkbook.Windows(1).Caption
End Sub

ā€¦ Workbook_BeforeClose(Cancel As Boolean)

ElseIf withoutcancel = True Then
ReturnValue = MsgBox("close application and register in the new window. save data?", vbYesNo + vbQuestion, "myapp")
Select Case ReturnValue
Case vbYes
ActiveWorkbook.Save
Case vbNo
End Select
ThisWorkbook.Saved = True
Dim RetVal
RetVal = Shell(PathToFile("myapp.exe  -enterkey"), 1)
Else
1 Like