Forum Discussion

A2Z CF's avatar
A2Z CF
Brass Contributor
Apr 26, 2023
Solved

Sending Enter Key

Hi everyone,

I have the macro in Excel which does the series of things fine but at the end where it supposed to open an external application it terminates. That external application is opening fine but since it has one of the libraries files missing, it appears as a pop up to hit Enter on the OK option. When I hit Enter, the macro seems to be not reaching to the End Sub which is next line. I tried to send enter key through Macro by SendKey command, but I think I am not using it correctly. Any help in this regard will be appreciated.

 

VBA.Shell "Explorer.exe C:\Users\Documents\My Application", vbNormalNoFocus

 

Thank you so much.

  • A2Z CF 

    Here’s an example of how you could modify your code to send the Enter key to the external application:

    VBA.Shell "Explorer.exe C:\Users\Documents\My Application", vbNormalNoFocus
    Application.Wait (Now + TimeValue("0:00:02")) ' Wait for 2 seconds
    Application.SendKeys "{ENTER}", True

    This example, use the Application.Wait method to pause the macro for 2 seconds before sending the Enter key. This gives the external application time to open and become the active window.

     

    Or

    Application.SendKeys "{ENTER}"

    Please, keep in mind that the SendKeys command can sometimes be unpredictable and may not work as expected.

     

    Alternatively, you can try using a different library file for the external application to avoid the pop-up message altogether. If that's not possible, you could consider using a different method to open the application, such as the Shell command, which may allow you to bypass the pop-up message.

     

     

    I hope this helps!

     

3 Replies

  • NikolinoDE's avatar
    NikolinoDE
    Platinum Contributor

    A2Z CF 

    Here’s an example of how you could modify your code to send the Enter key to the external application:

    VBA.Shell "Explorer.exe C:\Users\Documents\My Application", vbNormalNoFocus
    Application.Wait (Now + TimeValue("0:00:02")) ' Wait for 2 seconds
    Application.SendKeys "{ENTER}", True

    This example, use the Application.Wait method to pause the macro for 2 seconds before sending the Enter key. This gives the external application time to open and become the active window.

     

    Or

    Application.SendKeys "{ENTER}"

    Please, keep in mind that the SendKeys command can sometimes be unpredictable and may not work as expected.

     

    Alternatively, you can try using a different library file for the external application to avoid the pop-up message altogether. If that's not possible, you could consider using a different method to open the application, such as the Shell command, which may allow you to bypass the pop-up message.

     

     

    I hope this helps!

     

    • A2Z CF's avatar
      A2Z CF
      Brass Contributor

      Great! Thank you so much. This works amazing by increasing the wait time to about 20 sec, just one problem, when the application opens, it turns off the Num Lock and Insert on the keyboard. How can this Macro turn on the Num Lock and Insert again. Thank you

Resources