[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

11/07/2009 at 07:14AM PST, ID: 24880460
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.1

Excel Instances- Refering to the Instance in VBA

Asked by kyle972 in Microsoft Excel Spreadsheet Software

Tags: Excel, VBA

I need to open multiple instances of excel and be able to control each instance in VBA. I currently am storing the information for each instance when it is opened so that I can refer back to it. The problem with this approach is:

1. You have to open the instance using VBA in order to have a reference to it
2. It is unstable, any VBA error will erase the public variables where the instances are stored as "Microsoft Excel"
3. No way to store distinguishing instance information in a spreadsheet..because all instance variables are "Microsoft Excel"

I have found the following code that returns the handle for each excel instance running and stores it in an array. (This is a good start to being able to distinguish each instance and not have to deal with the generic "Microsoft Excel" reference. The two things I am looking for:

1. How do I take the handle information for each instance being stored in the array and use that in VBA to control that instance?

2. I need to be able to distinguish the instances so I know what handle refers to what instance. Perhaps through a workbook name in that instance or some other method so I know what instance of excel each handle is referring to.

My end goal:

Be able to record instance variables or handles into a spreadsheet with some unique identifiers so I can then reference that spreadsheet and pull the correct instance information to control the instance in VBA. I do not want to have to store everything in public variables or have to open the instance from VBA in order to have the ability to refer to it.



1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
Option Explicit 
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long 
Private Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) As Long 
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public hWndArray() As Long 

Private Const GW_HWNDNEXT = 2 
 
Sub xlInstances() 
  Dim hwnd As Long, lRet As Long
  'Dim hWndArray() As Long
  Dim i As Integer
  Dim sClassBuffer As String 
  i = 0
  hwnd = FindWindow("XLMAIN", vbNullString)
  If hwnd <> 0 Then
    ReDim hWndArray(i)
    hWndArray(i) = hwnd
    Do
      hwnd = GetNextWindow(hwnd, GW_HWNDNEXT)
      If hwnd = 0 Then Exit Sub
      sClassBuffer = String(255, 0)
      lRet = GetClassName(hwnd, sClassBuffer, Len(sClassBuffer))
      sClassBuffer = Left(sClassBuffer, InStr(1, sClassBuffer, Chr(0), vbTextCompare) - 1)
      If UCase(sClassBuffer) = "XLMAIN" Then
        i = i + 1
        ReDim Preserve hWndArray(i)
        hWndArray(i) = hwnd
      End If
    Loop
  End If 
 
 
End Sub
[+][-]11/08/09 12:48 AM, ID: 25769840

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/08/09 12:36 PM, ID: 25771765

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/08/09 04:16 PM, ID: 25772691

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Excel Spreadsheet Software
Tags: Excel, VBA
Sign Up Now!
Solution Provided By: StellanRosengren
Participating Experts: 3
Solution Grade: A
 
 
[+][-]11/08/09 06:20 PM, ID: 25773039

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/09/09 03:05 AM, ID: 25774832

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/09/09 06:39 AM, ID: 25776260

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20090824-EE-VQP-74 - Hierarchy / EE_QW_3_20080625