>nHwnd = FindWindow("XLMAIN", Application.Caption)
Since XL 2000, the Application object exposes the HWnd of the XLMAIN
window, so FindWindow is not necessary.
Dim L As Long
L = Application.HWnd
Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
On Tue, 16 Mar 2010 12:08:19 -0000, "Peter T" <peter_t@discussions>
wrote:
>simply
>pplication.hWnd in xl2002 or later,
>
> in earlier and/or all versions
>
>Private Declare Function FindWindow Lib "user32.dll" _
> Alias "FindWindowA" ( _
> ByVal lpClassName As String, _
> ByVal lpWindowName As String) As Long
>
>sub test()
>dim nHwnd as long
>nHwnd = FindWindow("XLMAIN", Application.Caption)
>end sub
>
>In passing, unless you really know what you are doing and have cast iron
>error handling I strongly recommend you don't use LockWindowUpdate,
>particularly if distributing.
>
>Regards,
>Peter T
>
>"Paul W Smith" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>>I have seen code in the past which uses an windows API to lock the screen
>>
>> I found the code below which apparently does this.
>>
>> However it does not work or more accurately the LockWindowUpdate
>> ThisApplication.MainFrameHWND line gives a "Object does not support this
>> property or method" error.
>>
>> How do I correct this?
>>
>>
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> Paste the following declaration at the top of your module:
>>
>> Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As
>> Long) As Long
>>
>> And then use these lines of code in your macro to lock and unlock screen
>> updates:
>>
>> ' Locks window updates
>> LockWindowUpdate ThisApplication.MainFrameHWND
>>
>> ' Unlocks window updates
>> LockWindowUpdate 0
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>
>
Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com