ThisWorkbook populate with Code Q

S

Seanie

Would anyone know what the part-code below debugs at "FindWindow" -
I'm using Excel 2007 and code worked perfectly in 2003

Sub Populate_TW()

Dim StartLine As Long
Dim msg1 As String, msg2 As String

Dim VBEHwnd As Long
On Error GoTo ErrH:
Application.VBE.MainWindow.Visible = False
VBEHwnd = FindWindow("wndclass_desked_gsk", _
Application.VBE.MainWindow.Caption)
If VBEHwnd Then
LockWindowUpdate VBEHwnd
End If
.......
........
End Sub
 
C

Chip Pearson

That looks like some of my code. What sort of problem are you having?
Exactly what error messages do you receive? The code works fine for me
in Excel 2007.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
S

Seanie

It sure is Chip, probably all of it. I have used it successfully with X
\l 2003 but since I upgraded to XL 2007 it hasn't worked. It debugs on
"FindWindow" and I don't know why as I haven't changed any of the
code. Two things I remember that were required for it to work on 2003
was Trust Access to the VBA object and a reference within VB to MS VB
extensibility. I've confirmed both are checked but I get this error
 
P

Peter T

Is the FindWindow API declared and available in your for use in module

but why not simply

VBEHwnd = Application.VBE.MainWindow.Hwnd

Regards,
Peter T
 
S

Seanie

Below, exactly as in my 2003 workbook, which worked

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal ClassName As String, ByVal WindowName As String) As Long
Private Declare Function LockWindowUpdate Lib "user32" _
(ByVal hWndLock As Long) As Long
 
P

Peter T

That looks fine assuming of course you are calling the APIs from within the
same module.

You didn't answer Chip's question about what error you get.

Did you try reading directly as I suggested -

VBEHwnd = Application.VBE.MainWindow.Hwnd

(even in Excel97)

Regards,
Peter T
 
S

Seanie

Yes, its within the same module.

Error I am getting is on text "findWindow" with message Sub or
Function not defined
 
P

Peter T

Head the module containing the APIs and the code 'Option Explicit' and do
Debug / Compile. It will probably blow in the same place.

What is your OS, 64 bit per chance (not that I could say why that should
matter)

Third time, have you tried returning the hWnd directly from MainWindow as
suggested.

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top