Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / August 2007

Tip: Looking for answers? Try searching our database.

problem with DetectExcel

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Allen_N - 31 Aug 2007 05:16 GMT
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
'69 Camaro - 31 Aug 2007 06:03 GMT
Hi, Al.

> the call to FindWindow raises the error: "Sub or
> Function not defined".

If the FindWindow( ) function is an alias for the FindWindowA API function,
then the function must be declared in one of the following ways:

1.)  Publicly, if the function is called from procedures located in other
modules, or
2.)  Privately or publicly, if the function is called from procedures within
the same module.

Otherwise, FindWindow( ) must be defined as a user-defined function.  It's
not a built-in function.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
Blogs: www.DataDevilDog.BlogSpot.com, www.DatabaseTips.BlogSpot.com
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
Allen_N - 31 Aug 2007 06:48 GMT
Thanks, Gunny.

I'll have to start hunting for the definition in my other MDBs and ADPs.

> Hi, Al.
>
[quoted text clipped - 20 lines]
> http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
> info.
'69 Camaro - 31 Aug 2007 07:04 GMT
Hi, Al.

> I'll have to start hunting for the definition in my other MDBs and ADPs.

All the declarations I could find use a string as the second argument, not a
Long data type:

Private Declare Function FindWindow Lib "user32" Alias _
   "FindWindowA" (ByVal strClass As String, _
   ByVal lpWindow As String) As Long

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
Blogs: www.DataDevilDog.BlogSpot.com, www.DatabaseTips.BlogSpot.com
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.