A
Allen_N
Previously, I have used the following code (from a book) successfully. In my
current MDB, however, the call to FindWindow raises the error: "Sub or
Function not defined". I don't remember ever having to explicitly declare Win
API functions from within VB or VBA. Am I missing a reference?
Thanks!
--Al
Sub DetectExcel()
' Detects a running instance of Excel and registers it.
' pre-25/06/07.
Const WM_USER = 1024
Dim hwnd As Long
' If Excel is running this API call returns its handle.
hwnd = FindWindow("XLMAIN", 0)
If hwnd = 0 Then ' 0 means Excel not running.
Exit Sub
Else
' Excel is running so use the SendMessage API
' function to enter it in the Running Object Table.
SendMessage hwnd, WM_USER + 18, 0, 0
End If
End Sub
current MDB, however, the call to FindWindow raises the error: "Sub or
Function not defined". I don't remember ever having to explicitly declare Win
API functions from within VB or VBA. Am I missing a reference?
Thanks!
--Al
Sub DetectExcel()
' Detects a running instance of Excel and registers it.
' pre-25/06/07.
Const WM_USER = 1024
Dim hwnd As Long
' If Excel is running this API call returns its handle.
hwnd = FindWindow("XLMAIN", 0)
If hwnd = 0 Then ' 0 means Excel not running.
Exit Sub
Else
' Excel is running so use the SendMessage API
' function to enter it in the Running Object Table.
SendMessage hwnd, WM_USER + 18, 0, 0
End If
End Sub