Results 1 to 5 of 5

Thread: Excel Interacting With Another Non-Office Application

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Member
    Join Date
    May 2013
    Posts
    31
    Rep Power
    0
    Obviously, you have posted a snippet. For the FindWindow() API routine to work, it needs to be defined at the top of a Module before other code. That code can vary depending on 32bit or 64bit computers.
    e.g. for 32 bit:
    Code:
    Declare Function FindWindow Lib "user32" Alias _
    "FindWindowA" (ByVal lpClassName As String, _
                        ByVal lpWindowName As Long) As Long
    For SendKeys() to work properly, it that is even possible, be sure that you turn off Windows, UAC.

    For a more robust API example:
    Code:
    #If VBA7 Then
        Dim mhwndForm As LongPtr            'The userform's window handle
        Private Declare PtrSafe Function FindWindow32 Lib "USER32" Alias "FindWindowA" (ByVal lpClassName As String, _
        ByVal lpWindowName As String) As LongPtr
        Private Declare PtrSafe Sub SetWindowPos Lib "USER32" (ByVal hwnd As LongPtr, ByVal hWndInsertAfter As LongPtr, _
        ByVal X As Long, ByVal Y As Long, ByVal cx As Long, _
        ByVal cy As Long, ByVal wFlags As Long)
        Private Const HWND_TOPMOST As LongPtr = -1
        Private Const HWND_NOTOPMOST As LongPtr = -2
    #Else
        Dim mhwndForm As Long             'The userform's window handle
        Private Declare Function FindWindow32 Lib "USER32" Alias "FindWindowA" (ByVal lpClassName As String, _
        ByVal lpWindowName As String) As Long
        Private Declare Sub SetWindowPos Lib "USER32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
        ByVal X As Long, ByVal Y As Long, ByVal cx As Long, _
        ByVal cy As Long, ByVal wFlags As Long)
        Private Const HWND_TOPMOST As Long = -1
        Private Const HWND_NOTOPMOST As Long = -2
    #End If
    Private Const SWP_NOSIZE             As Long = &H1
    Private Const SWP_NOMOVE             As Long = &H2
    Private Const SWP_NOACTIVATE             As Long = &H10
    Private Const SWP_SHOWWINDOW             As Long = &H40
    Last edited by Kenneth Hobson; 07-02-2013 at 11:36 PM.

Similar Threads

  1. Add VBA Reference From Another Application Excel To PowerPoint
    By ds1001 in forum Rajan Verma's Corner
    Replies: 1
    Last Post: 06-02-2013, 02:43 PM
  2. Replies: 1
    Last Post: 02-14-2013, 11:08 AM
  3. Replies: 2
    Last Post: 12-04-2012, 02:05 PM
  4. Using Office.CommandBar
    By Rasm in forum Excel Help
    Replies: 2
    Last Post: 12-03-2011, 06:04 AM
  5. Excel Application.OnKey With Parameter
    By Excel Fox in forum Excel Help
    Replies: 0
    Last Post: 11-29-2011, 01:31 PM

Posting Permissions

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