Advertisement

07.15.2008 at 08:00PM PDT, ID: 23568387
[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.2

How to find the Hwnd of the VB editor window of Excel (long explanation, but my quest is short)

Asked by ahammar in Visual Basic Programming, Microsoft Excel Spreadsheet Software, Microsoft Visual Basic.Net

Tags:

Hello all,
LONG Explanation....but my quest is short

Keep in mind, I haven't used API's very much...

What I want to do is really quite short, this is just explained more than it needs to be...I simply want to find a window, and close it...but read this before you try and answer...I know how to do it normally...but not in this case...

My attempt:
I am trying to get the Hwnd of the VB editor window of Excel by using the FindWindow API in VBA (which is the same way I would do it with VB6)
then close it using the PostMessage API (of course still the same as VB6)...I took the PostMessage  call out of the sub in the code I posted for now...

I have posted my code below...it is just the 2 API's, the constants/variables, then the sub that simply pops up a message box giving me the Hwnd of the vb editor window while Module1 is active (which of course right now is always 0).

This works fine on any window that has a normal Hwnd (or what I know as normal), but using some 3rd party software, I have found that the Hwnd of the VB editor window also contains a letter, or maybe 2 (don't remember for sure now, but that doesn't matter how many), which I didn't know Hwnd's used letters....so I assume that since the FindWindow API returns a long variable type, that's why it doesn't work, but I don't know that for sure...

So, my question is mainly, how do I get the Hwnd of the VB editor window of Excel.
The window title I used in my code below is the exact caption of the VB editor window of my app if I have module 1 open.  That is the one I want to find the Hwnd of, and then close it...

The PostMessage API also returns a Long variable type, so I assume it will not work on this window either to close it...

Just 2 things, find that window, and close it...

How do I do that?

Thanks!
:-)
Albert


Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
 
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
    
    Private Const WM_QUIT = &H12
    Private WinHwnd As Long
 
 
'Sub that gets ran
Sub CloseWindow()
    Dim iReturn As Integer
    WinHwnd = FindWindow(vbNullString, "Microsoft Visual Basic - Test.xls - [Module1 (Code)]")
MsgBox WinHwnd
 
End Sub
[+][-]07.15.2008 at 11:33PM PDT, ID: 22013638

View this solution now by starting your 7-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

Zones: Visual Basic Programming, Microsoft Excel Spreadsheet Software, Microsoft Visual Basic.Net
Tags: VB6
Sign Up Now!
Solution Provided By: zorvek
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.16.2008 at 02:39AM PDT, ID: 22014424

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.16.2008 at 05:22AM PDT, ID: 22015134

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 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 - Hierarchy / EE_QW_2_20070628