SBendBuckeye
Programmer
This code was included in some Microsoft Access help about using Access as an automation server. The example starts up Excel. The main code checks for an existing instance with this line of code:
Set objMyXL = GetObject(, "Excel.Application"
After error checking, it then invokes the following sub. What is it actually doing and what is the impact if I don't include such code in my own automation projects?
Thanks in advance for any help you can give me!
************************** Begin Code *******************
'Procedure dectects running Excel instance and registers it
Private Sub DetectExcel()
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 'DetectExcel
************************** End Code *********************
Set objMyXL = GetObject(, "Excel.Application"
After error checking, it then invokes the following sub. What is it actually doing and what is the impact if I don't include such code in my own automation projects?
Thanks in advance for any help you can give me!
************************** Begin Code *******************
'Procedure dectects running Excel instance and registers it
Private Sub DetectExcel()
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 'DetectExcel
************************** End Code *********************