ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help with a quick way to close all duplicate windows using VBA please (https://www.excelbanter.com/excel-programming/377536-help-quick-way-close-all-duplicate-windows-using-vba-please.html)

[email protected]

Help with a quick way to close all duplicate windows using VBA please
 
I am trying to figure out a way to close all duplicate windows of
workbooks using VBA
I thought this would work but it doesn't.

For Each wb In Workbooks
If Windows.Count 1 Then
For i = 1 To Windows.Count
Windows(2).Close
Next i
End If
Next wb

For example: I have 3 workbooks wb1, wb2, wb3 and with wb3 I have 2
windows open so there are acutally 4 windows total. wb1, wb2, wb3:1,
wb3:2

I only want to close wb3:2. And would prefer to do it without having
to actually activate each workbook.

Any help is greatly appreciated.


Dave Peterson

Help with a quick way to close all duplicate windows using VBAplease
 
Maybe...

Dim iCtr As Long
Dim wb As Workbook

For Each wb In Application.Workbooks
For iCtr = wb.Windows.Count To 2 Step -1
wb.Windows(iCtr).Close
Next iCtr
Next wb



wrote:

I am trying to figure out a way to close all duplicate windows of
workbooks using VBA
I thought this would work but it doesn't.

For Each wb In Workbooks
If Windows.Count 1 Then
For i = 1 To Windows.Count
Windows(2).Close
Next i
End If
Next wb

For example: I have 3 workbooks wb1, wb2, wb3 and with wb3 I have 2
windows open so there are acutally 4 windows total. wb1, wb2, wb3:1,
wb3:2

I only want to close wb3:2. And would prefer to do it without having
to actually activate each workbook.

Any help is greatly appreciated.


--

Dave Peterson

[email protected]

Help with a quick way to close all duplicate windows using VBA please
 
Worked great - thanks for the help.


Dave Peterson wrote:
Maybe...

Dim iCtr As Long
Dim wb As Workbook

For Each wb In Application.Workbooks
For iCtr = wb.Windows.Count To 2 Step -1
wb.Windows(iCtr).Close
Next iCtr
Next wb



wrote:

I am trying to figure out a way to close all duplicate windows of
workbooks using VBA
I thought this would work but it doesn't.

For Each wb In Workbooks
If Windows.Count 1 Then
For i = 1 To Windows.Count
Windows(2).Close
Next i
End If
Next wb

For example: I have 3 workbooks wb1, wb2, wb3 and with wb3 I have 2
windows open so there are acutally 4 windows total. wb1, wb2, wb3:1,
wb3:2

I only want to close wb3:2. And would prefer to do it without having
to actually activate each workbook.

Any help is greatly appreciated.


--

Dave Peterson




All times are GMT +1. The time now is 02:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com