Excel 2013 vba multiple monitor configuration, close all windows except a specific one

Hello experts,

I have a multiple monitor setup, and trying to close all windows except a specific one.
So assuming the sheets open are in:

How do I replace the “Monitors.xlsm” with the current file name?
Make Windows("CurrentfileName.xlsm:1") the active window?
and then close Windows 2 & 3?

Who is Participating?
Saurabh Singh TeotiaCommented:
To do what you can use the following code..it will close all the windows leaving the one which you specified not to close...

   Dim w As Window

    For Each w In ActiveWorkbook.Windows
        If w.Caption <> "Your window here which you want to keep open" Then w.Close
    Next w

Open in new window

Saurabh Singh TeotiaCommented:
You can use the following code..This will close all the workbooks..leaving the workbook open from which you are running this code..please change it basis of your requirement..

Also the workbooks it's closing it will save changes in them..

    Dim wb As Workbook

    For Each wb In Workbooks

        If wb.Name <> ThisWorkbook.Name Then wb.Close (True)

    Next wb

Open in new window

biker9Author Commented:
Sorry, that's not it, I am referring to closing open windows within the workbook, not closing the workbook itself.
biker9Author Commented:
Thank you, works perfectly!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.