Command line switch -enterkey


#1

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.


#2

What is already happening when you run the code above?


#3

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.


#4

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


#5

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.


#6

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


#7

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