Yes, you can print a list of files in an Excel file by using the TEXTJOIN function to create a clean, printable list. This method is ideal for creating a static reference sheet of file names and paths, perfect for sharing with colleagues or keeping in a physical binder. It avoids the clutter of hyperlinks and formatting issues that often appear when trying to print cells with active links, giving you a clean, readable document that printer drivers handle much better.
Method 1: The TEXTJOIN Formula Approach
This is the most robust and flexible method for creating a printable list. It allows you to control exactly what information is included in the list, such as the file name, the full path, or both, and how they are separated. The TEXTJOIN function is available in all modern versions of Excel for Windows, Mac, and Excel for the Web.
The core of this method is the CELL function, which grabs the file path from the current workbook. The TEXTJOIN function then takes that path and combines it with the file name from the cell you're referencing. This combination is then pasted as values, ensuring it remains static and printable.
Step-by-Step Implementation
- Prepare your data: Ensure you have a column of cell references in your Excel sheet. For example, the file names are in cells A2:A10. These cells should contain the file names themselves, not the full path.
- Insert a new column: Add a column next to your file names. Let's say your file names are in column A. Click on the header for column B to make it active.
- Enter the TEXTJOIN formula: In the first cell of your new column (B2), type the following formula exactly:
=TEXTJOIN("", TRUE, CELL("filename", A2), A2)
- Understand the formula:
TEXTJOIN("", TRUE, ...): This tells Excel to join the items together with no separator (empty string) and to ignore empty cells.CELL("filename", A2): This function retrieves the full file path of the workbook that contains the cell A2. It is crucial that cell A2 is within the same workbook as your formula is being entered into.A2: This is the file name from your data list.
- Fill down the formula: Double-click the small square handle in the bottom-right corner of cell B2 to copy the formula down to the last row of your data. This will generate a full path for each file name in column A.
- Convert to values: Select your new column (B:B) and press Ctrl + C to copy. Then, right-click on the same range and choose Paste Special > Values. This step is critical. It permanently replaces the formulas with their results, preventing any future changes to your file names from updating the list.
- Print the list: Go to the File > Print menu. Your list of full file paths is now ready to be printed. You can also use Ctrl + P to open the print dialog directly. You can adjust margins, orientation, and scaling as needed.
Why This Method is Superior
This approach is preferred because it creates a clean, printable text string. When you print a cell with a hyperlink, many printer drivers will attempt to include the full URL as a separate line of text, which can look messy and waste paper. The TEXTJOIN method produces a single, clean line of text for each file, which is much more professional and easier to read.
Method 2: The Power Query Approach
For users who are comfortable with Excel's Power Query (also known as Get & Transform), this method offers a more programmatic and scalable solution. It is particularly useful when you need to manage a large number of files or when the file names are not in a simple contiguous column but are scattered throughout the workbook. Power Query can handle these complexities with ease.
This method involves creating a query that iterates through all cells in a specific range, extracts the file names, and then concatenates them into a single list. This list can then be exported to a new sheet or directly printed.
Step-by-Step Implementation
- Open Power Query: Go to the Data tab on the ribbon and click on Get Data > From Table/Range. Select the range of cells that contains your file names. This creates a new query in the Power Query Editor.
- Add a custom column: In the Power Query Editor, click on the Add Column tab and select Custom Column.
- Enter the custom column formula: In the custom column formula editor, paste the following formula:
Table.ColumnNames(Source)
- Expand the custom column: Click the double arrow icon next to the new "Custom" column header to expand it. Uncheck the "Use original column name as prefix" box and click OK. This will expand the list of column names into individual rows.
- Filter or select the desired data: If your source table contains more than just the file names, you can filter the column to include only the rows you want. For example, you can select only the column that contains your file names.
- Convert to a list: With the desired rows selected, right-click on the column header and choose Convert to List. This will convert the selected rows into a single list of values.
- Concatenate the list: Click on the Transform tab and select Combine Columns > Concatenate. Choose a separator if you want a space or a comma between the items, or leave it blank for a continuous string.
- Load the data: Click on the Home tab and select Close & Load > Close & Load To.... Choose Only Create Connection or Table depending on your needs. This will create a new table in your workbook containing your printed list.
- Print the new table: Select the new table and go to File > Print to print your list.
When to Use Power Query
Power Query is the tool of choice when you need to process data beyond a simple list. It is excellent for cleaning, transforming, and combining data from multiple sources. If your file names are not in a simple column, if you need to filter based on other criteria, or if you are working with a very large dataset, this method is far more powerful and reliable than the formula approach.
Method 3: The VBA Macro Approach
For advanced users, a VBA (Visual Basic for Applications) macro provides the ultimate level of control. This method can be customized to handle virtually any file naming convention or formatting requirement. It runs a script that loops through your data, constructs the full path, and outputs it to a new sheet.
This approach is not for the faint of heart. It requires a basic understanding of VBA syntax and how to run macros in Excel. However, once set up, it can be incredibly efficient and can automate the entire process with a single click.
Step-by-Step Implementation
- Open the VBA Editor: Press Alt + F11 to open the VBA Editor window.
- Insert a new module: In the VBA Editor, go to Insert > Module to create a new module.
- Paste the VBA code: Copy and paste the following VBA code into the new module window:
Sub PrintFileList()
Dim wsSource As Worksheet
Dim wsOutput As Worksheet
Dim rngData As Range
Dim i As Long
Dim lastRow As Long
Dim fileFullName As String
' Set the source worksheet
Set wsSource = ActiveSheet
' Set the output worksheet
On Error Resume Next
Set wsOutput = ThisWorkbook.Worksheets("FileList")
On Error GoTo 0
If wsOutput Is Nothing Then
Set wsOutput = ThisWorkbook.Worksheets.Add(After:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count))
wsOutput.Name = "FileList"
End If
' Clear previous data
wsOutput.Cells.Clear
' Find the last row of data in the source worksheet
lastRow = wsSource.Cells(wsSource.Rows.Count, "A").End(xlUp).Row
' Set the range of data to process
Set rngData = wsSource.Range("A2:A" & lastRow)
' Loop through each cell in the range
For i = 1 To rngData.Rows.Count
' Get the full file path and name
fileFullName = CELL("filename", rngData.Cells(i, 1)) & rngData.Cells(i, 1).Value
' Write the result to the output worksheet
wsOutput.Cells(i, 1).Value = fileFullName
Next i
' Print the output worksheet
wsOutput.PrintOut
MsgBox "File list printed successfully!", vbInformation
End Sub
- Run the macro: Return to your Excel workbook. Press Alt + F8 to open the Macro dialog box. Select the PrintFileList macro and click Run.
- Review the output: The macro will create a new sheet named "FileList" containing the full paths of your files. It will also send this sheet to your default printer. A message box will confirm the successful execution.
Customizing the Macro
The provided code is a starting point. You can easily customize it to suit your specific needs. For example, you can change the separator between the path and the file name by modifying the fileFullName variable. You can also change the output sheet's name or the range of cells to be processed. This flexibility is what makes VBA a powerful tool for automating repetitive tasks.
How to Choose
Choosing the right method comes down to your technical comfort level, the size of your dataset, and whether you need ongoing automation.
For most users, the TEXTJOIN formula approach is the best balance of simplicity, power, and ease of use. It requires no knowledge of programming, provides excellent results, and is easy to modify as your data changes. It is the recommended method for anyone who needs to create a clean, printable list of file names and paths on a regular basis.
The Power Query approach is the superior choice for complex data processing, large datasets, or when you need to perform transformations beyond simple concatenation. If you find yourself frequently cleaning and combining data from multiple sources, investing time in learning Power Query will pay off in the long run.
The VBA macro approach is reserved for advanced users who need a high degree of customization and automation. If you are comfortable with VBA and have specific requirements that cannot be met with formulas or Power Query, then a macro is the solution. However, for most users, the complexity of writing and maintaining a VBA script outweighs its benefits.
Frequently Asked Questions
Does this work on Excel for the Web?
Yes, the TEXTJOIN formula method works perfectly in Excel for the Web. Power Query is also available in Excel for the Web, making it a viable option for users on that platform. VBA macros, however, are not supported in Excel for the Web.
What if my file names are in a different column?
Simply adjust the cell reference in your formula. For example, if your file names are in column C, change the formula in cell B2 to =TEXTJOIN("", TRUE, CELL("filename", C2), C2). Similarly, you can update the VBA code to loop through column C instead of column A.
Can I print just the file names without the full path?
Absolutely. If you only want the file names, you can modify the TEXTJOIN formula to only include the second argument. For example, =TEXTJOIN("", TRUE, A2). This will just print the file name from the cell.
Why does the CELL("filename") function return an error?
The CELL function will return an error if the workbook has not been saved yet. It only works on the currently open, saved workbook. Ensure your Excel file has been saved before using this method.
Can I use this to print a list of files from a different folder?
No, the methods described here work only on the files that are currently open in the Excel workbook. They cannot scan or list files from your hard drive or a network folder that are not currently open in Excel.
Final Thoughts
Crafting a clean, printable list of file names and paths is a valuable skill for anyone who works with data. It bridges the gap between the digital and physical worlds, making information easy to share, archive, and reference. By using the TEXTJOIN formula, you can quickly and easily create professional-looking lists without the need for complex programming or formatting hacks.
The method we've covered is not just about printing; it's about presenting your data in its best possible light. A clean list is easier to read, less prone to errors, and looks much more professional than a spreadsheet full of active links. Whether you are creating a master index for a project, archiving a collection of documents, or simply need a hard copy for a meeting, this technique provides a reliable and efficient solution.