+ Reply to Thread
Results 1 to 2 of 2

Returning User Control to Excel from other Application in VBA

  1. #1

    Returning User Control to Excel from other Application in VBA

    Hi.

    I'm using Excel VBA to control both Excel and another application.
    However, there are times when I want to control whether Excel or the
    other application is the 'active' application and the one displaying on
    the screen. (I pop up a user form in Excel, but the user has to click
    Excel in the windows toolbar to activate it before they see the form).

    How do I return control back to Excel from the other application?

    Thanks!


  2. #2
    AA2e72E
    Guest

    RE: Returning User Control to Excel from other Application in VBA

    An API call may give you the control you seek:

    Declare Function SetActiveWindow Lib "user32.dll" (ByVal hwnd As Long) As Long

    If you are using Excel 2003, hwnd is a property of the application object.
    For the other application (and other versions of Excel), you need to find its
    HWND property. If it is not an exposed property, use the API call FINDWINDOW:
    it MAY give you its handle:

    Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
    lpClassName As String, ByVal lpWindowName As String) As Long

    PS: the lpclassname for Excel parameter for ALL versions of Excel is XLMAIN.

    "[email protected]" wrote:

    > Hi.
    >
    > I'm using Excel VBA to control both Excel and another application.
    > However, there are times when I want to control whether Excel or the
    > other application is the 'active' application and the one displaying on
    > the screen. (I pop up a user form in Excel, but the user has to click
    > Excel in the windows toolbar to activate it before they see the form).
    >
    > How do I return control back to Excel from the other application?
    >
    > Thanks!
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1