View Single Post
  #12   Report Post  
Posted to microsoft.public.excel.programming
keepITcool keepITcool is offline
external usenet poster
 
Posts: 2,253
Default clear intermediate window automatically

Bob, great idea..

and he could even do without the classmodule...and do it all in
ThisWorkbook.(as it is an object module THUS a class module it allows
withevents objects.

I looked up the faceID for an Eraser icon, and minimalized your code
to following:

'<<Thisworkbook module
Private WithEvents CbE As CommandBarEvents

Sub VBEMenu()
With Application.VBE.CommandBars("Standard")
On Error Resume Next
.FindControl(Tag:="ImmClear").Delete
On Error GoTo 0

With .Controls.Add(temporary:=True)
.Tag = "ImmClear"
.Caption = "Clear Immediate Window"
.Style = msoButtonIcon
.FaceId = 1964
Set CbE = Application.VBE.Events.CommandBarEvents(.Control)
End With
End With
End Sub

Private Sub CbE_Click(ByVal CommandBarControl As Object, _
Handled As Boolean, CancelDefault As Boolean)
Select Case LCase$(CommandBarControl.Tag)
Case "immclear": ClearImmediateWindow
End Select
End Sub

Private Sub Workbook_Open()
VBEMenu
End Sub



keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"Bob Phillips" wrote :

You could do, but remember that you will want to run it from the VB
IDE, so probably best to create a toolbar button, as MZ-Tools does.
Here is how to do it

First, insert a class module with this code

Private WithEvents CbE As CommandBarEvents

Private Sub CbE_Click(ByVal CommandBarControl As Object, _
Handled As Boolean, _
CancelDefault As Boolean)

Select Case CommandBarControl.Caption
Case "Clear Immediate Window": ClearImmediateWindow
End Select

End Sub

Sub AddNewMenuItem()
Dim oCB As CommandBar
Dim oCbCtl As CommandBarControl

Set oCB = Application.VBE.CommandBars("Standard")
Set oCbCtl = oCB.Controls.Add(temporary:=True)
With oCbCtl
.Caption = "Clear Immediate Window"
.Style = msoButtonCaption
End With
Set CbE = Application.VBE.Events.CommandBarEvents(oCbCtl)

End Sub

and then put this code in a standard module to load the commandbar

Public cCbE As clsCbE

Sub AddVBECommandbars()
Set cCbE = New clsCbE
cCbE.AddNewMenuItem
End Sub

Call AddVBECommandbars from you Workbok_Open