printing all workbooks names in one shot

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi
The code below is to print each workbook's name. If I have 5 then it will msgbox these 5 files names. I want to improve this code so it can print all the name in one shot (not 5 msgboxs or whatever the number of the files). Is that possible? Thank you so much.

Code:
Sub wb_names()
    'to find workbook name
    Dim x As Integer
    Dim y As Integer
    x = Workbooks.Count
    For y = 1 To x
        MsgBox Workbooks(y).Name
    Next y
End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Code:
Sub lezawang()
  Dim asName()      As String
  Dim i             As Long

  ReDim asName(1 To Workbooks.Count)
  For i = 1 To Workbooks.Count
    asName(i) = Workbooks(i).Name
  Next i
  
  MsgBox Join(asName, vbLf)
End Sub
 
Upvote 0
Thank you very much. The code is working perfect. I have 1 question please

Join(asName, vbLf)

Does that tell vba to join "each member" of the array with line feed? So I do not need to put that line of code in a loop. Thanks again
 
Upvote 0
Look at VBA Help for the Join function and post back if you still have questions.
 
Upvote 0

Forum statistics

Threads
1,213,534
Messages
6,114,186
Members
448,554
Latest member
Gleisner2

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