Create files from excel list

  1. 06-28-2015, 03:17 PM


    #1

    moretvicar is offline


    Registered User


    Question Create files from excel list

    Hi All
    Is it possible to crate multiple worksheets from a list of cells?

    Eg in cells A1 to A12 I have various different dates (using . as the separator).
    I would like to create a workbook named as each of these dates in the same folder as the original workbook that contains the list — can it be done?


  2. 06-28-2015, 09:33 PM


    #2

    Re: Create files from excel list

    yes

    though you need to be clear about whether you are talking about multiple worksheets or workbooks?

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.


  3. 06-28-2015, 09:48 PM


    #3

    Catman50 is offline


    Registered User


    Re: Create files from excel list

    Hi Moretvicar

    I have attached a workbook with the code to do this.


  4. 06-29-2015, 01:34 AM


    #4

    moretvicar is offline


    Registered User


    Re: Create files from excel list

    Sorry I meant to say create workbooks ie a new file for each cell value.


  5. 06-29-2015, 01:46 AM


    #5

    Re: Create files from excel list

    catman50’s file should do just as you asked


best product lists

LoginAsk is the ultimate resource for all your login-related questions and issues. Whether you’re having trouble with forgotten passwords, account lockouts, or security breaches, we have the answers you need. Explore our guides, tips, and tools to streamline your login process and stay secure online.

  • About us
  • Contact Us
  • Privacy Policy

JADownie

Active Member

Joined
Dec 11, 2007
Messages
394


  • #1

Hello —

I have a file which lists out 305 unique client ids starting in Row 1. For each of these ids, I need to create a new excel workbook with and save it to a location with the name of the id value in column A. I really don’t want to have to manually create 305 files now, so I was hoping maybe someone had a macro or shortcut that they could suggest for me here? I just want to save each new file to My Documents now — C:Documents and SettingsAA.BBMy DocumentsFinal Files

Thanks in advance for any helps and tips here today!

I want to create excel files with the given set of names.

Given names stored in Names.xls at A1:A8 =

  1. Wall -CMU
  2. Wall — Painting
  3. Wall — Exterior Siding
  4. Wall — Insulation
  5. Pipe — Copper
  6. Pipe — Ductile Iron
  7. Pipe — CPVC
  8. Tank — Sodium Bisulphate

I want to create a new excel file, rename it based on the given name list, save and close it and then jump to next file.

The code below is only to create the first file:

Sub AddNewWorkbook1()
    'Adding New Workbook
    Workbooks.Add
    'Saving the Workbook
    ActiveWorkbook.SaveAs Filename:="C:UsersgoktemDesktopChange OrdersWall - CMU.xls"
    Close
End Sub

I need to write a code to choose the filename from the given name list and create a loop.

How can I do that?

YowE3K's user avatar

YowE3K

23.8k7 gold badges26 silver badges40 bronze badges

asked Jan 30, 2017 at 16:24

George Gokmen's user avatar

You would need to play with where the list is etc, but just create a simple loop.

Sub AddNewWorkbook1()
Dim wbName as String

'Adding New Workbook
    For i = 1 to 8
        wbName = Cells(i, 1).Value
        Workbooks.Add
'Saving the Workbook
        ActiveWorkbook.SaveAs Filename:="C:UsersgoktemDesktopChange Orders" & wbName & ".xls"
        Close
    Next i
End Sub

answered Jan 30, 2017 at 16:30

Tim Wilkinson's user avatar

Tim WilkinsonTim Wilkinson

3,73111 gold badges33 silver badges62 bronze badges

1

You probably don’t need this every day: But once a file you might want to have a list of all files within a folder or directory in Excel. The good thing: There are many methods available. If you Google it, you will find a lot of different methods to create a file list in Excel. But unfortunately, all of them have advantages and disadvantages – which you usually only find out after trying them. That’s the reason for this article: You won’t only learn each method step by step: You will rather find an overview comparing all the advantages and disadvantages of each method. After seeing this, you don’t need to start extensive trials and errors. Much better: You can easily select the method that works best for you!

Summary

Method 1:
Copy & Paste on Mac
Method 2:
Named function
Method 3:
Internet browser
Method 4:
PowerQuery
Method 5:
Excel-Add-In
Method 6:
Windows PowerShell
Method 7:
VBA Macro
Short description Copy and paste from the Mac Finder. Use a function in a named range to insert a file list. Open folder with a web browser and copy the file list. Use PowerQuery to insert a directory. Let an Excel add-in do the work for you. Use the Windows built-in PowerShell feature. Use a VBA Macro to insert a file list.
Ease of use
Operating system Mac Windows Windows / Mac Windows / Mac Windows Windows Windows
Include subfolders
and files
No No No Yes Yes Yes (Yes) (depends on the VBA macro)
File information available File names File names File names, file links (not working properly), file size, date modified Folder path, name
extension, date accessed, date modified, date created
More attributes:

Content type, kind, size, ReadOnly, hidden, S
system, directory, archive, device, normal, temporary, SparseFile, ReparsePoint, compressed, offline, NotContentIndexed, encrypted, ChangeTime, SymbolicLink, MountPoint

Links to files on the drive, file path, date and time last saved, date and time created, file size, file type File name, file path, date and time last saved, file size Depends on the VBA macro
Technology Mac Finder Named function in Excel Internet browser PowerQuery Excel Add-In PowerShell, Text Import Wizard VBA
Comment Fast but with limited options. Only shows files, no folders. File links not working in our test; not working with all internet browsers (tested with Google Chrome and working). Elegant and uses built-in functions. Convenient, fast and many options. Results not good, difficult process; performs well on large file structures, though. Modifying the macro rather for advanced users.
Link Click here Click here Click here Click here Click here Click here Click here

Method 1: Simply copy and paste from Mac Finder to Excel

File list on a Mac: Just copy and paste from Finder to Excel.
File list on a Mac: Just copy and paste from Finder to Excel.

This first method works on a Mac only: Just select all files in a Finder window and press copy (Command + C on the keyboard). Next, switch to Excel and paste the list: Press Command + V on the keyboard.

The advantage of this method is that it’s very easy and fast. Unfortunately, you don’t have any further options than just pasting the file names. That means you can’t insert data of subfolders or file properties.

Recommendation: Use this if you need a quick file list on the Mac – without any further information.

Method 2: Insert a file list with built-in Excel functions using “Named Ranges”

The second method is actually quite elegant: Use built-in Excel functions to insert a file list in Excel. It is built on advanced functions, such as an Excel function within a named range. But following these steps should be quite straight-forward.

Set up the named range

Create a list of all files with Excel built-in features. Here: A function within a named range.
Create a list of all files with Excel built-in features. Here: A function within a named range.
  1. Choose a cell in which you later write the folder path. In this case, it’s cell C4.
  2. Click on “Defined Name” on the Formulas ribbon.
  3. Give a name for the cell containing the folder path (here: “Folder_Path”)
  4. In the “Refers to” field, type: =files(linktopathcell) (replace “linktopathcell” with your cell reference – in this case “Method_2!$C$4”).
  5. Confirm with OK.

Use the named range in Excel functions

Copy the folder path from Windows Explorer.
Copy the folder path from Windows Explorer.
  1. Go to the Windows Explorer and copy the folder path.
As the last step, set up a INDEX formula that pulls the file names into cells.
As the last step, set up a INDEX formula that pulls the file names into cells.
  1. Paste the folder link into the folder path cell (the cell you have set as the named range in step 1 above). Add one of the following endings:
    • If you want to include all files – no matter which file type – in your list, add *
    • For listing only Excel files, add *.xls*
    • If you want to see all files ending on “.xlsx”, add *.xlsx
  2. As the last step, enter an INDEX function for compiling the list (here in cell B7):
    =INDEX(Folder_Path,ROW(B1))
    Folder_Path should be the same name that you have given in step 3 above. The ROW function should refer to any cell in the first row (for example to B1). That means, this argument could also be A1, C1, etc.
    As the last step: Copy the INDEX function down until you see the first #REF error. #REF means in this case that there are no more files in your folder. If you like, you could wrap the IFERROR function around in order to mitigate the error.

Recommendation: Use this if you only need a list of files (no subfolders) that dynamically updates itself.

Method 3: Use an internet browser to quickly copy and paste a file list to Excel

I must say, I like this idea because it’s almost as fast as our method number 1 above: Open a folder in a webbrowser and then copy & paste the list to Excel.

Copy the folder path from Windows Explorer.
Copy the folder path from Windows Explorer.
  1. Copy the folder path from the Windows Explorer like on the screenshot or Mac Finder (for Mac: open file Info (right-click on folder and then on “Get Info”. Select and copy link from “Where” section).
Open the folder path with a web browser. Then copy and paste the file list into Excel.
Open the folder path with a web browser. Then copy and paste the file list into Excel.
  1. Open a browser, for example Google Chrome (should be working with most other browsers as well). Paste the previously copied link into the address field.
  2. Copy the table of files.
  3. Open Excel and paste the file list.

One comment to this methods: The links (which are also created) usually won’t work in Excel.

Recommendation: Use this if you quickly need a file list (without subfolders), including some file properties such as file size and date last saved.

Method 4: Create a file list with PowerQuery

PowerQuery can also create lists of all files and folders, including subfolders.
PowerQuery can also create lists of all files and folders, including subfolders.

The next method is also among my favorites: It uses PowerQuery and comes with the advantages that it doesn’t require any complex programming or third-party technologies. Also, it can be refreshed easily later on.

  1. Go to the Data ribbon, click on “Get Data” on the left, and select “From Folder” in the “From File” sub-menu.
  2. Select the Folder and click on “Open” (not in the screenshot on the right).
  3. You can now see a preview. Click on “Transform Data”.
Above that, PowerQuery allows to insert various file attributes.
Besides that, PowerQuery allows to insert various file attributes.
  1. Remove the first column “Content” (right-click on the heading and click on “Remove”).
  2. If you want to see more file attributes than shown already in the preview, click on the small arrows of the “Attributes” column and select the attributes.
  3. Click on Close & Load.

Recommendation: Use this method if you to have lots of file properties. It can later on easily be refreshed.

The Excel add-in Professor Excel Tools offers a function to easily insert directories. It regards subfolders and can insert various file properties:

  • Links to files on the drive
  • File path
  • Date and time last saved
  • Date and time created
  • File size
  • File type
The Excel add-in Professor Excel Tools provides a function to insert a directory in Excel.
The Excel add-in Professor Excel Tools provides a function to insert a directory in Excel.

You can further specify, where the directory should be created.

Using the “Get Directory” function is very simple:

  1. Click on the Directory button on the Professor Excel ribbon.
  2. Select all the file properties you’d like to show and the location, where the directory table should be placed in your Excel file.
  3. Click on “Select folder and start”. Then, choose the folder and proceed with ok.

That’s it. Please feel free to download Professor Excel Tools here.

Recommendation: Use this method if you accept third-party add-ins within Excel. If you do, it’s quite convenient and fast.


Professor Excel Tools Box

This function is included in our Excel Add-In ‘Professor Excel Tools’

(No sign-up, download starts directly)


As you can see in the following description, using PowerShell takes quite a lot of steps. It might be useful, though, if you have very large folder structures. Otherwise, try to use a different method.

Open PowerShell and write the directory into a text file

The PowerShell method is very complex. First open the folder in PowerShell and paste a line of code.
The PowerShell method is very complex. First open the folder in PowerShell and paste a line of code.
  1. Navigate to the folder which you want to have the file list from. Hold down the Shift key on the keyboard and right-click on it (if you don’t hold down the Shift key, the option of “Open PowerShell window here” is not available).
  2. Click on “Open PowerShell window here”.
  3. Copy and paste the following code and press enter afterwards:
Get-ChildItem -Path $MyInvocation.MyCommand.Path -force -recurse > filelist.txt

Import text file into Excel

Open Microsoft Excel.

Next, import a text file containing the directory into Excel.
Next, import a text file containing the directory into Excel.
  1. Open the Text Import Wizard: Go to the Data ribbon, click on “Get Data” on the left, then on “Legacy Wizards” and then on “From Text (Legacy)”. If this option is not available, you can activate it within the Excel settings (check this article for more information).
  2. Select the file filelist.txt from your folder. In step 3 above it was created within your target folder.
Fine-tune the import so that all files are shown correctly.
Fine-tune the import so that all files are shown correctly.

Follow the import steps of the Text Import Wizard on the screen:

  1. In the first step of three, make sure that “Fixed width” is selected. Click on Next.
  2. In the lower part of the window, Excel shows a preview of your import. Check here, if the column separators are set correctly: You can move the vertical lines if necessary or add more by clicking on the respective number in the heading of the preview. Then click on Next and in the third step Next again. After that finish the Text Import Wizard by selecting the location where the file list should be placed.
  3. As you can see in number 8, the file list is inserted, but has some disadvantages: Directory paths are cut, each subfolder has its own block, and so on.

In a nutshell: This method of creating file lists within Microsoft Excel via PowerShell is complex and the results aren’t as good as in the other methods.

Recommendation: Try to avoid this method.


Do you want to boost your productivity in Excel?

Get the Professor Excel ribbon!

Add more than 120 great features to Excel!


Method 7: Let a VBA Macro loop through the files

The following VBA code creates a list of all files in a folder. The list will be placed on the currently active worksheet, starting from cell A1. Please make sure that you don’t override anything here.

Sub InsertFileList()

Dim objFileSystemObject As Object, objFolder As Object, objFile As Object, i As Integer

Set objFileSystemObject = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFileSystemObject.GetFolder("Your folder path")

For Each objFile In objFolder.Files
    i = i + 1
    ActiveSheet.Cells(i, 1) = objFile.Name
Next

End Sub
Insert a new module in VBA.
Insert a new module in VBA.

Here is how to use the VBA-Code. If you need more help of how to use VBA macros, please refer to this article.

  1. Copy the VBA code from above.
  2. Open the VBA editor by pressing Alt + F11 on the keyboard.
  3. Insert a new module: Right-click on the active workbook name on the left.
  4. Go to “Insert” and click on “Module”.
Paste the code sample from above, replace "Your folder path" and run the macro.
Paste the code sample from above, replace “Your folder path” and run the macro.
  1. Paste the code by pressing Ctrl + V on the keyboard.
  2. Replace Your folder path with the path from your own folder.
  3. Click on start in the VBA editor.

Download

download, arrow

Please feel free to download all examples from above in this comprehensive Excel workbook. Each method is located on a different worksheet. Just click here and the download starts.

Image by Pexels from Pixabay

Понравилась статья? Поделить с друзьями:
  • Create field in word document
  • Create excel with php
  • Create excel with java
  • Create excel from template
  • Create excel from php