Consulting

Results 1 to 8 of 8

Thread: Create text files with file names from excel column

  1. #1
    VBAX Regular
    Joined
    Nov 2018
    Posts
    6
    Location

    Create text files with file names from excel column

    Hi guys I would appreciate help with VBA code to create many text files named out of cells in a column within an excel sheet. Any ideas?

  2. #2
    Hello
    Can you give more details please?

  3. #3
    VBAX Regular
    Joined
    Nov 2018
    Posts
    6
    Location
    Quote Originally Posted by YasserKhalil View Post
    Hello
    Can you give more details please?
    Hi, so I have a list of file names in an excel spreadsheet and I want help to find code that will create blank text files that are named after the spreadsheet. Like one file per cell containing a file name.

  4. #4
    Try this code
    Sub Test()
        Dim fso As Object, txtFil As Object, c As Range
    
    
        Set fso = CreateObject("Scripting.FileSystemObject")
        
        For Each c In Range("A1:A3")
            Set txtFil = fso.CreateTextFile(ThisWorkbook.Path & "\" & c.Value & ".txt", True)
            txtFil.Close
        Next c
    End Sub

  5. #5
    VBAX Regular
    Joined
    Nov 2018
    Posts
    6
    Location
    Quote Originally Posted by YasserKhalil View Post
    Try this code
    Sub Test()
        Dim fso As Object, txtFil As Object, c As Range
    
    
        Set fso = CreateObject("Scripting.FileSystemObject")
        
        For Each c In Range("A1:A3")
            Set txtFil = fso.CreateTextFile(ThisWorkbook.Path & "\" & c.Value & ".txt", True)
            txtFil.Close
        Next c
    End Sub
    Hi, where will the new text file be created and saved?

  6. #6
    The new created text files will be in the same path of your workbook (ThisWorkbook.Path) >> you can change to your folder like that ("C:\MyFolder")

  7. #7
    VBAX Regular
    Joined
    Nov 2018
    Posts
    6
    Location
    Quote Originally Posted by YasserKhalil View Post
    The new created text files will be in the same path of your workbook (ThisWorkbook.Path) >> you can change to your folder like that ("C:\MyFolder")
    You're a legend. The code was perfect and I learned.

  8. #8
    You're welcome. Glad I can offer some help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •