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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
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
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
Hello,
I appretiate if you can help on this one
I am using combobox1 instead of msg box.
I need to do exactly as the above, as in removing ThisWorkBook from the item listing

My code as as follows:

Dim wkb as Workbook
For each wkb in Application.Workbooks
.Additem wkb.name
Next wkb
End with
Thanks in advance
 
Upvote 0
Sorry but I thought it was relevant, so I continued on here.
Sorry.
Also still appreciate your help if its possible.
 
Upvote 0
VBA Code:
'
'To be located in worksheet code module, assumes a worksheet activeX combobox control named ComboBox1
'
Sub ListOpenWorkbooksExample()
    Dim WB As Workbook

    With Me.ComboBox1
        .Clear
        For Each WB In Application.Workbooks
            Select Case WB.Name
            Case ThisWorkbook.Name
            Case Else
                .AddItem WB.Name
            End Select
        Next WB

        If .ListCount > 0 Then
            .ListIndex = 0
            MsgBox .ListCount & " open workbooks", vbInformation, "Open Workbooks"
        Else
            MsgBox "No workbooks are open", vbExclamation, "Open Workbooks"
        End If
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,375
Messages
6,124,579
Members
449,174
Latest member
chandan4057

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