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:
Windows("Monitors.xlsm:1")
Windows("Monitors.xlsm:2")
Windows("Monitors.xlsm:3")

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?

Thanks,
biker9
biker9Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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


Saurabh...
0
biker9Author Commented:
Sorry, that's not it, I am referring to closing open windows within the workbook, not closing the workbook itself.
0
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...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
biker9Author Commented:
Thank you, works perfectly!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.