PC Review


Reply
Thread Tools Rate Thread

How to clear Immediate Window programmatically within a procedure?

 
 
joeu2004
Guest
Posts: n/a
 
      29th Jan 2008
I know that I can clear the Immediate Window by selecting the window,
then pressing ctrl+A Delete (or ctrl+X).

Is there some way to clear the Immediate Window programmatically
within a procedure?
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      29th Jan 2008
Cntl A highlist the entire active worksheet. You can do the same witth

ActiveSheet.Cells.Select

You can clear the entire sheet with this

ActiveSheet.Cells.ClearContents


"joeu2004" wrote:

> I know that I can clear the Immediate Window by selecting the window,
> then pressing ctrl+A Delete (or ctrl+X).
>
> Is there some way to clear the Immediate Window programmatically
> within a procedure?
>

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      29th Jan 2008
Here is something I got some time ago

Option Explicit

Private Declare Function GetWindow Lib "user32" ( _
ByVal hWnd As Long, _
ByVal wCmd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
Private Declare Function GetKeyboardState Lib "user32" ( _
pbKeyState As Byte) As Long
Private Declare Function SetKeyboardState Lib "user32" ( _
lppbKeyState As Byte) 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_KEYDOWN As Long = &H100
Private Const KEYSTATE_KEYDOWN As Long = &H80

Private savState(0 To 255) As Byte

Public Sub ClearImmediateWindow()
Dim hPane As Long
Dim tmpState(0 To 255) As Byte

hPane = GetImmHandle
If hPane = 0 Then MsgBox "Immediate Window not found."
If hPane < 1 Then Exit Sub

'Save the keyboardstate
GetKeyboardState savState(0)

'Sink the CTRL (note we work with the empty tmpState)
tmpState(vbKeyControl) = KEYSTATE_KEYDOWN
SetKeyboardState tmpState(0)
'Send CTRL+End
PostMessage hPane, WM_KEYDOWN, vbKeyEnd, 0&
'Sink the SHIFT
tmpState(vbKeyShift) = KEYSTATE_KEYDOWN
SetKeyboardState tmpState(0)
'Send CTRLSHIFT+Home and CTRLSHIFT+BackSpace
PostMessage hPane, WM_KEYDOWN, vbKeyHome, 0&
PostMessage hPane, WM_KEYDOWN, vbKeyBack, 0&

'Schedule cleanup code to run
Application.OnTime Now + TimeSerial(0, 0, 0), "DoCleanUp"

End Sub

Private Sub DoCleanUp()
' Restore keyboard state
SetKeyboardState savState(0)
End Sub

Private Function GetImmHandle() As Long
'This function finds the Immediate Pane and returns a handle.
'Docked or MDI, Desked or Floating, Visible or Hidden
Dim oWnd As Object, bDock As Boolean, bShow As Boolean
Dim sMain$, sDock$, sPane$
Dim lMain&, lDock&, lPane&

On Error Resume Next
sMain = Application.VBE.MainWindow.Caption
If Err <> 0 Then
MsgBox "No Access to Visual Basic Project"
GetImmHandle = -1
Exit Function
End If

For Each oWnd In Application.VBE.Windows

If oWnd.Type = 5 Then

bShow = oWnd.Visible
sPane = oWnd.Caption
If Not oWnd.LinkedWindowFrame Is Nothing Then
bDock = True
sDock = oWnd.LinkedWindowFrame.Caption
End If
Exit For
End If
Next

lMain = FindWindow("wndclass_desked_gsk", sMain)
If bDock Then
'Docked within the VBE
lPane = FindWindowEx(lMain, 0&, "VbaWindow", sPane)
If lPane = 0 Then
'Floating Pane.. which MAY have it's own frame
lDock = FindWindow("VbFloatingPalette", vbNullString)
lPane = FindWindowEx(lDock, 0&, "VbaWindow", sPane)
While lDock > 0 And lPane = 0
lDock = GetWindow(lDock, 2) 'GW_HWNDNEXT = 2
lPane = FindWindowEx(lDock, 0&, "VbaWindow", sPane)
Wend
End If
ElseIf bShow Then
lDock = FindWindowEx(lMain, 0&, "MDIClient", vbNullString)
lDock = FindWindowEx(lDock, 0&, "DockingView", vbNullString)
lPane = FindWindowEx(lDock, 0&, "VbaWindow", sPane)
Else
lPane = FindWindowEx(lMain, 0&, "VbaWindow", sPane)
End If

GetImmHandle = lPane

End Function



--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"joeu2004" <(E-Mail Removed)> wrote in message
news:224bc33f-3b30-4ebb-bac3-(E-Mail Removed)...
>I know that I can clear the Immediate Window by selecting the window,
> then pressing ctrl+A Delete (or ctrl+X).
>
> Is there some way to clear the Immediate Window programmatically
> within a procedure?



 
Reply With Quote
 
joeu2004
Guest
Posts: n/a
 
      30th Jan 2008
On Jan 29, 3:44*am, "Bob Phillips" <bob....@somewhere.com> wrote:
> Here is something I got some time ago
> [....nearly 100 lines of code elided....]


Thanks. I was hoping for something more straight-forward. Not your
fault, of course. Thanks again.
 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      30th Jan 2008
It is straight-forward. You don't have to work out how to do it, or how it
works. All you have to do is add the code and then call the procedure. Being
large doesn't stop it from being straight-forward, it just makes it large.

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"joeu2004" <(E-Mail Removed)> wrote in message
news:33320d3b-ef1a-4690-a86c-(E-Mail Removed)...
On Jan 29, 3:44 am, "Bob Phillips" <bob....@somewhere.com> wrote:
> Here is something I got some time ago
> [....nearly 100 lines of code elided....]


Thanks. I was hoping for something more straight-forward. Not your
fault, of course. Thanks again.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to programmatically clear network passwords from IE ocb@earthling.net Windows XP Internet Explorer 3 26th Sep 2006 11:10 PM
How to programmatically clear network passwords from IE ocb@earthling.net Windows XP Internet Explorer 0 26th Sep 2006 02:34 PM
How to programmatically clear network passwords from IE ocb@earthling.net Windows XP Internet Explorer 0 26th Sep 2006 02:33 PM
clear out a date programmatically Leif Microsoft Access VBA Modules 3 22nd Jul 2004 01:02 PM
Programmatically Clear Internet History Steve Windows XP General 9 6th Nov 2003 05:34 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:34 PM.