VBA List Open Unsaved Workbooks in Excel. It helps to know all open and unsaved workbooks name. It is easy shift between unsaved workbooks. We have an option to open multiple workbooks in MS Office Excel. Let us see in the following tutorial how to list all open unsaved Workbook names in Excel VBA.
Here is the following syntax to loop through all Workbooks in Excel VBA.
For Each Workbook in Application.Workbooks Statements... Next
Where Workbook: It represents Workbook object which is part of workbooks collection.
Let us see the following example macro to List all Open unsaved Workbooks in Excel VBA.
'VBA List All Open Unsaved Workbooks in Excel Sub VBA_List_All_Open_Unsaved_Workbooks() 'Variable declaration Dim xWorkbook As Workbook 'Loop through all workbooks For Each xWorkbook In Application.Workbooks 'Check Workbook is current Workbook or not If xWorkbook.Name <> ThisWorkbook.Name Then 'Check if the file names has an extension If InStr(Right(xWorkbook.Name, 5), ".xl") > 0 Then 'Save and Close Workbook xWorkbook.Close SaveChanges:=True Else Debug.Print xWorkbook.Name End If End If Next End Sub
Here are the instructions to use above macro procedure in Visual basic editor.
- Save Visual Basic Editor(VBE) by clicking Alt +F11
- Go to code window by clicking F7
- Copy above specified macro or procedure
- Paste above copied code in code window
- Run macro by clicking F5 or Run command
- You can see output on the Immediate Window (Ctrl+G) screen
You may also like the related Workbook Object articles.