How to delete "Extra" Windows in Excel

  • Hi guys


    Obviously all must b aware that in an XL File New windows can b created by clicking on "window"Menu and then selecting "New Window".


    I created som windows for a very important office file and now I want to remove the same. However I just havent been able to figure out how to remove / disable a window permanently. I am aware that these windows can be hidden but still I would like to know how to remove them permanently.


    Can someone pl guide me as to how to remove a window? Is there any macro for it????? any guidance would be immensely appreciated


    thanx


    ciao

  • Hi xl_spec


    The following code will prevent the creation of any new windows:


    Private Sub Workbook_WindowActivate(ByVal Wn As Excel.Window)
    Do Until ThisWorkbook.Windows(1).Caption = ThisWorkbook.Name
    Wn.Close
    Loop
    End Sub


    Place it in the ThisWorkbook module and give it a try.


    Hope this helps...

    Regards
    Fredrik

  • Hi FWind.....


    sorry....but the code actually threw up an error when I ran it in the actual XL File. It worked perfectly in the experimental files i had created......


    when I run this code in the actual Excel File (that incidentally contains more than 800 Macros) I get a "Compile Error....Cant find Project or Library" on the wn.close line....


    As far as my knowledge goes this error relates to something like "Microsoft Excel Object Library" and MS Office OL" not being ticked in the References menu in macros


    But believe me both are ticked and the code works on other XL files but not this.....


    now where it is getting botched up?????


    pl guide me....


    again a million thanx

  • Hmm...


    I have to put on my thinking cap...
    I'll check a few things and come back later today...


    Perhaps you can use ActiveWindow.Close instead of wn.Close - just a thought, I haven't tried it yet.

    Regards
    Fredrik

  • Hi xl_spec


    The (ByVal Wn as Excel.Window)-part is perhaps not version safe (I'm on XL97), but if you exchange "Wn.Close" to "ActiveWindow.Close" you ought to get the same result. (At least I got it :wink1: )

    Regards
    Fredrik