View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Peter T[_7_] Peter T[_7_] is offline
external usenet poster
 
Posts: 162
Default Error in VB Editor Coding


"Tim Childs" wrote in message
Hi

I have used the code below to close the extra VB windows that end up
being open when using the VBA editor.

Sub CloseVBEWindows()
Dim W As VBIDE.Window

ThisWorkbook.VBProject.VBE.MainWindow.SetFocus
For Each W In Application.VBE.Windows
If W.Type = vbext_wt_CodeWindow Or W.Type = vbext_wt_Designer Then
If Application.VBE.ActiveWindow.Caption < W.Caption Then
W.Close
End If
End If
Next W
End Sub

It works fine on a 64-bit laptop running Windows 10 and Excel 2010.
When I run it on a 64-bit laptop with windows 7 and Excel Professional
Plus I get the error 424 (object required) at the following line:
If W.Type = vbext_wt_CodeWindow Or W.Type = vbext_wt_Designer Then

The extensibility library 5.3 has been set in references.

Can anyone suggest a possible solution, please


That ought to work, I have something similar (and more to collapse all
projects). Curious though why you get that error there and not on the for
each line. If there was anything wrong with the reference you would have got
a compile error. When it breaks see what W refers to in Locals, alt-v, s

If you want to try Mike's suggestion and declare W as object, also change
the named vbext constants to 0 and 1 respectively (or simply if W.Type <= 1)
to rule out the extensibility reference.

Peter T