Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching multiple Excel Instances

Status
Not open for further replies.

ActMod

Technical User
Aug 25, 2003
45
US

The following suggested macro works great with respect to activating an open Excel workbook when Access recognizes the appropriate Excel instance. Unfortunately, more often
than not, my opened Excel document is apparently in an instance that Access does not recognize. Is there any code that can help sort thru all open instances of Excel in search of an open Excel Workbook? Or, is there some other workaround to this problem

Thank you for any help.

Dim XLApp As Excel.Application
Dim WB As Excel.Workbook
Dim NumWkBks As Integer

Set XLApp = GetObject(, "Excel.Application")

NumWkBks = Workbooks.Count

For Each WB In XLApp.Workbooks
If WB.Name = "C:\MyDocuments\MyExcel.xls" Then

Sheets(1).Select

End If
Next WB


 
GetObject only grabs the first instance of Excel and there is no other built-in method for instantiating an OLE object besides CreateObject that I know of.

There are ways to locate the active instances using the API but all you can retrieve from these functions are the window handles (hwnd). If you can figure out how to instantiate an OLE object using a window handle, I'd be interested in knowing how.

This might be a good question for a C++ forum.


VBSlammer
redinvader3walking.gif

[sleeping]Unemployed in Houston, Texas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top