PC Review


Reply
Thread Tools Rate Thread

Clearing Immediate window in VBA by code

 
 
Madiya
Guest
Posts: n/a
 
      24th Mar 2008
I am using some debug.print statements in my code which prints current
value of my variables in the immediate window.
When I run the code again, I have to manually select all and delete
the values from the immediate window.

Is there any way by which I can just run the code to clear the
immediate window?

Thanks and Regards,
Madiya
 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      24th Mar 2008
Sadly you can't do it programatically

Mike

"Madiya" wrote:

> I am using some debug.print statements in my code which prints current
> value of my variables in the immediate window.
> When I run the code again, I have to manually select all and delete
> the values from the immediate window.
>
> Is there any way by which I can just run the code to clear the
> immediate window?
>
> Thanks and Regards,
> Madiya
>

 
Reply With Quote
 
Anant Basant
Guest
Posts: n/a
 
      24th Mar 2008
try the following code.

Sub DelInImmedate()
Debug.Print Now
Application.SendKeys "^g ^a {DEL}"
End Sub
--
Regards,
Anant


"Madiya" wrote:

> I am using some debug.print statements in my code which prints current
> value of my variables in the immediate window.
> When I run the code again, I have to manually select all and delete
> the values from the immediate window.
>
> Is there any way by which I can just run the code to clear the
> immediate window?
>
> Thanks and Regards,
> Madiya
>

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      24th Mar 2008
very nice i never thought of sendkeys

"Anant Basant" wrote:

> try the following code.
>
> Sub DelInImmedate()
> Debug.Print Now
> Application.SendKeys "^g ^a {DEL}"
> End Sub
> --
> Regards,
> Anant
>
>
> "Madiya" wrote:
>
> > I am using some debug.print statements in my code which prints current
> > value of my variables in the immediate window.
> > When I run the code again, I have to manually select all and delete
> > the values from the immediate window.
> >
> > Is there any way by which I can just run the code to clear the
> > immediate window?
> >
> > Thanks and Regards,
> > Madiya
> >

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      24th Mar 2008
Yes you can, without SendKeys too. here is some code from KeepItCool a while
back

Option Explicit


'<--- Excel Version --->
' Code in a standard module


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


Sub ClearImmediateWindow()
'Adapted by keepITcool
'Original from Jamie Collins fka "OneDayWhen"
'http://www.dicks-blog.com/excel/2004/06/clear_the_immed.html


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


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


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
' Excel2003: Registry Editor (Regedit.exe)
' HKLM\SOFTWARE\Microsoft\Office\11.0\Excel\Security
' Change or add a DWORD called 'AccessVBOM', set to 1
' Excel2002: Tools/Macro/Security
' Tab 'Trusted Sources', Check 'Trust access..'
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)



"Mike H" <(E-Mail Removed)> wrote in message
news:2DEF7D0E-80E0-474A-978B-(E-Mail Removed)...
> Sadly you can't do it programatically
>
> Mike
>
> "Madiya" wrote:
>
>> I am using some debug.print statements in my code which prints current
>> value of my variables in the immediate window.
>> When I run the code again, I have to manually select all and delete
>> the values from the immediate window.
>>
>> Is there any way by which I can just run the code to clear the
>> immediate window?
>>
>> Thanks and Regards,
>> Madiya
>>



 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      24th Mar 2008
Interseting,

I had always taken as read the information on Chip Pearson's site:-

Unfortunately, there is no way to programmatically clear the Immediate
Window. This is a shortcoming that has frustrated many programmers
http://www.cpearson.com/excel/Debug.htm

Thanks for the information

Mike


"Bob Phillips" wrote:

> Yes you can, without SendKeys too. here is some code from KeepItCool a while
> back
>
> Option Explicit
>
>
> '<--- Excel Version --->
> ' Code in a standard module
>
>
> 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
>
>
> Sub ClearImmediateWindow()
> 'Adapted by keepITcool
> 'Original from Jamie Collins fka "OneDayWhen"
> 'http://www.dicks-blog.com/excel/2004/06/clear_the_immed.html
>
>
> 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
>
>
> Sub DoCleanUp()
> ' Restore keyboard state
> SetKeyboardState savState(0)
> End Sub
>
>
> 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
> ' Excel2003: Registry Editor (Regedit.exe)
> ' HKLM\SOFTWARE\Microsoft\Office\11.0\Excel\Security
> ' Change or add a DWORD called 'AccessVBOM', set to 1
> ' Excel2002: Tools/Macro/Security
> ' Tab 'Trusted Sources', Check 'Trust access..'
> 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)
>
>
>
> "Mike H" <(E-Mail Removed)> wrote in message
> news:2DEF7D0E-80E0-474A-978B-(E-Mail Removed)...
> > Sadly you can't do it programatically
> >
> > Mike
> >
> > "Madiya" wrote:
> >
> >> I am using some debug.print statements in my code which prints current
> >> value of my variables in the immediate window.
> >> When I run the code again, I have to manually select all and delete
> >> the values from the immediate window.
> >>
> >> Is there any way by which I can just run the code to clear the
> >> immediate window?
> >>
> >> Thanks and Regards,
> >> Madiya
> >>

>
>
>

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      24th Mar 2008
If you had MZ-Tools Mike, you would know it is possible, he has a button to
do it.

--
---
HTH

Bob


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



"Mike H" <(E-Mail Removed)> wrote in message
news:3F393124-AB45-43F9-B3C6-(E-Mail Removed)...
> Interseting,
>
> I had always taken as read the information on Chip Pearson's site:-
>
> Unfortunately, there is no way to programmatically clear the Immediate
> Window. This is a shortcoming that has frustrated many programmers
> http://www.cpearson.com/excel/Debug.htm
>
> Thanks for the information
>
> Mike
>
>
> "Bob Phillips" wrote:
>
>> Yes you can, without SendKeys too. here is some code from KeepItCool a
>> while
>> back
>>
>> Option Explicit
>>
>>
>> '<--- Excel Version --->
>> ' Code in a standard module
>>
>>
>> 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
>>
>>
>> Sub ClearImmediateWindow()
>> 'Adapted by keepITcool
>> 'Original from Jamie Collins fka "OneDayWhen"
>> 'http://www.dicks-blog.com/excel/2004/06/clear_the_immed.html
>>
>>
>> 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
>>
>>
>> Sub DoCleanUp()
>> ' Restore keyboard state
>> SetKeyboardState savState(0)
>> End Sub
>>
>>
>> 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
>> ' Excel2003: Registry Editor (Regedit.exe)
>> ' HKLM\SOFTWARE\Microsoft\Office\11.0\Excel\Security
>> ' Change or add a DWORD called 'AccessVBOM', set to 1
>> ' Excel2002: Tools/Macro/Security
>> ' Tab 'Trusted Sources', Check 'Trust access..'
>> 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)
>>
>>
>>
>> "Mike H" <(E-Mail Removed)> wrote in message
>> news:2DEF7D0E-80E0-474A-978B-(E-Mail Removed)...
>> > Sadly you can't do it programatically
>> >
>> > Mike
>> >
>> > "Madiya" wrote:
>> >
>> >> I am using some debug.print statements in my code which prints current
>> >> value of my variables in the immediate window.
>> >> When I run the code again, I have to manually select all and delete
>> >> the values from the immediate window.
>> >>
>> >> Is there any way by which I can just run the code to clear the
>> >> immediate window?
>> >>
>> >> Thanks and Regards,
>> >> Madiya
>> >>

>>
>>
>>



 
Reply With Quote
 
Jim Rech
Guest
Posts: n/a
 
      24th Mar 2008
That's very impressive but the way I'd want to use this is in testing some
code that did a lot of Debug.Prints and I wanted to start with a blank slate
each time.


Debug.Print "AAAAAAAAAAAAAAAAAA"
ClearImmediateWindow
Debug.Print "BBBBBBBBBBBBB"

I would expect this to leave B's in the Immediate window but it is left
blank. Even Do Events and Application.Wait before the second Debug didn't
help. So is this actually useful I wonder? Example?

--
Jim

"Bob Phillips" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
| Yes you can, without SendKeys too. here is some code from KeepItCool a
while
| back
|
| Option Explicit
|
|
| '<--- Excel Version --->
| ' Code in a standard module
|
|
| 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
|
|
| Sub ClearImmediateWindow()
| 'Adapted by keepITcool
| 'Original from Jamie Collins fka "OneDayWhen"
| 'http://www.dicks-blog.com/excel/2004/06/clear_the_immed.html
|
|
| 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
|
|
| Sub DoCleanUp()
| ' Restore keyboard state
| SetKeyboardState savState(0)
| End Sub
|
|
| 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
| ' Excel2003: Registry Editor (Regedit.exe)
| ' HKLM\SOFTWARE\Microsoft\Office\11.0\Excel\Security
| ' Change or add a DWORD called 'AccessVBOM', set to 1
| ' Excel2002: Tools/Macro/Security
| ' Tab 'Trusted Sources', Check 'Trust access..'
| 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)
|
|
|
| "Mike H" <(E-Mail Removed)> wrote in message
| news:2DEF7D0E-80E0-474A-978B-(E-Mail Removed)...
| > Sadly you can't do it programatically
| >
| > Mike
| >
| > "Madiya" wrote:
| >
| >> I am using some debug.print statements in my code which prints current
| >> value of my variables in the immediate window.
| >> When I run the code again, I have to manually select all and delete
| >> the values from the immediate window.
| >>
| >> Is there any way by which I can just run the code to clear the
| >> immediate window?
| >>
| >> Thanks and Regards,
| >> Madiya
| >>
|
|


 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      24th Mar 2008
I have it now, Thanks again

"Bob Phillips" wrote:

> If you had MZ-Tools Mike, you would know it is possible, he has a button to
> do it.
>
> --
> ---
> HTH
>
> Bob
>
>
> (there's no email, no snail mail, but somewhere should be gmail in my addy)
>
>
>
> "Mike H" <(E-Mail Removed)> wrote in message
> news:3F393124-AB45-43F9-B3C6-(E-Mail Removed)...
> > Interseting,
> >
> > I had always taken as read the information on Chip Pearson's site:-
> >
> > Unfortunately, there is no way to programmatically clear the Immediate
> > Window. This is a shortcoming that has frustrated many programmers
> > http://www.cpearson.com/excel/Debug.htm
> >
> > Thanks for the information
> >
> > Mike
> >
> >
> > "Bob Phillips" wrote:
> >
> >> Yes you can, without SendKeys too. here is some code from KeepItCool a
> >> while
> >> back
> >>
> >> Option Explicit
> >>
> >>
> >> '<--- Excel Version --->
> >> ' Code in a standard module
> >>
> >>
> >> 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
> >>
> >>
> >> Sub ClearImmediateWindow()
> >> 'Adapted by keepITcool
> >> 'Original from Jamie Collins fka "OneDayWhen"
> >> 'http://www.dicks-blog.com/excel/2004/06/clear_the_immed.html
> >>
> >>
> >> 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
> >>
> >>
> >> Sub DoCleanUp()
> >> ' Restore keyboard state
> >> SetKeyboardState savState(0)
> >> End Sub
> >>
> >>
> >> 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
> >> ' Excel2003: Registry Editor (Regedit.exe)
> >> ' HKLM\SOFTWARE\Microsoft\Office\11.0\Excel\Security
> >> ' Change or add a DWORD called 'AccessVBOM', set to 1
> >> ' Excel2002: Tools/Macro/Security
> >> ' Tab 'Trusted Sources', Check 'Trust access..'
> >> 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)
> >>
> >>
> >>
> >> "Mike H" <(E-Mail Removed)> wrote in message
> >> news:2DEF7D0E-80E0-474A-978B-(E-Mail Removed)...
> >> > Sadly you can't do it programatically
> >> >
> >> > Mike
> >> >
> >> > "Madiya" wrote:
> >> >
> >> >> I am using some debug.print statements in my code which prints current
> >> >> value of my variables in the immediate window.
> >> >> When I run the code again, I have to manually select all and delete
> >> >> the values from the immediate window.
> >> >>
> >> >> Is there any way by which I can just run the code to clear the
> >> >> immediate window?
> >> >>
> >> >> Thanks and Regards,
> >> >> Madiya
> >> >>
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      24th Mar 2008
Did that code work for you? All that happens for me is the date and time are
printed in the Immediate window... nothing is cleared.

Rick


"Mike H" <(E-Mail Removed)> wrote in message
news:67CFF25D-8CA8-4758-A710-(E-Mail Removed)...
> very nice i never thought of sendkeys
>
> "Anant Basant" wrote:
>
>> try the following code.
>>
>> Sub DelInImmedate()
>> Debug.Print Now
>> Application.SendKeys "^g ^a {DEL}"
>> End Sub
>> --
>> Regards,
>> Anant
>>
>>
>> "Madiya" wrote:
>>
>> > I am using some debug.print statements in my code which prints current
>> > value of my variables in the immediate window.
>> > When I run the code again, I have to manually select all and delete
>> > the values from the immediate window.
>> >
>> > Is there any way by which I can just run the code to clear the
>> > immediate window?
>> >
>> > Thanks and Regards,
>> > Madiya
>> >


 
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
clearing the immediate window Keith G Hicks Microsoft Access 3 17th Feb 2010 05:30 AM
Clearing the Debug window JPS Microsoft C# .NET 1 31st Oct 2007 04:06 PM
Clearing the output window John Sutor Microsoft C# .NET 0 30th Oct 2007 12:15 PM
Clearing the Immediate Window Rob Diamant Microsoft Access 3 11th Oct 2006 06:17 PM
Clearing the window James Microsoft C# .NET 1 15th Nov 2005 05:20 AM


Features
 

Advertising
 

Newsgroups
 


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