how to list all open workbooks within a message box except current workbook

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
563
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
As the title states, is possible to "list" all open workbooks but not include the current workbook.
After searching the web this is closest the following code is pretty close to what I am looking for, except it list each individual open workbook in a msgbox one at time. Which makes sense since the msgbox is within a For Loop but unfortunately it also includes the current workbook as well.
Thank you
Code:
Sub isAnyWorkbookOpen()
        
    Dim wb As Workbook
    Dim wbs As Workbooks
    
    Set wbs = Application.Workbooks
    
    For Each wb In wbs
        MsgBox wb.Name 
    Next wb
End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi,
try this update to your code

Code:
Sub isAnyWorkbookOpen()
        
    Dim wb As Workbook
    Dim wbs As Workbooks
    Dim msg As String
    
    Set wbs = Application.Workbooks
    
    For Each wb In wbs
        If wb.Name <> ThisWorkbook.Name Then msg = msg & wb.Name & Chr(10)
    Next wb
    
    MsgBox IIf(Len(msg) > 0, msg, "No workbooks Open"), 48, "Workbooks Open"
End Sub

Dave
 
Upvote 0

Forum statistics

Threads
1,203,198
Messages
6,054,073
Members
444,701
Latest member
PTDykman

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top