Create Files From Cell Content In Excel

In this post we will see how to create files from cell content in excel.

Suppose we have a list of file names in column A, and the contents for these files in column B. Now for each file in column A, we would like to create text file, where A is the title of the file and B, is the content of the file.

Basically we are creating excel file with the value in a cell and naming the file from the value in the adjacent cell.

In this example we are creating text file using excel VBA, but we can create a variety of file types.




Below is the data which we will use to create files by cell values.

excel data showing file contents in excel cells

Step 1

Open VB editor from Developer tab in excel as shown in the figure.

Open developer tab to write VBA to write code to create files from cell contents

Step 2

Insert a module in which we will write a VBA code to create files from cell content in excel.

Insert a module in the VB editor

Step 3

Now double click the newly created module to open that and paste the below code in the module.

    Sub Create_FIles()

    Dim X

    Dim lngRow As Long

    Dim StrFolder As String

    StrFolder = “D:\Excel Website”

    X = Range([a1], Cells(Rows.Count, 2).End(xlUp))

    For lngRow = 1 To UBound(X)

    Open StrFolder & “\” & X(lngRow, 1) & “.txt” For Output As #1

    Write #1, X(lngRow, 2)

    Close #1

    Next

    End Sub




vba code to create file name and file contents from values in cell

This vba code is creating files from the content that we have in cell, the code is iterating through all the rows and creating the file content from the value in column B and naming the text files with the name that we have in column A for each corresponding item.

You just need to modify the folder path location on the code and provide the folder path in which you would like to create files from the cell content.

Hope this helped.

 




Share The Knowledge

Random Posts

  • Create Rows From Comma Separated Cell Values In Excel

    create rows from comma separated values .in excel, split comma separated values and create rows from each value in excel, break comma separated string in a cell into rows, create rows from comma separated text string in excel

    Share The Knowledge
  • Create Files From Cell Content In Excel

    how to create file content from cell content i excel, excel vba to create file names from cell content, vba to create files from cell content, how to name file from cell content.

    Share The Knowledge
  • Remove Duplicate In Excel

    We have Product data in column A and you can see there are a lot of duplicates values, we want […]

    Share The Knowledge
  • Create Scrolling Table In Excel

    Let’s understand how to create a scrolling table in excel as shown below. The data that is used to create […]

    Share The Knowledge