+ Reply to Thread
Results 1 to 4 of 4

Run a folder with xls fles and save as txt files

Hybrid View

  1. #1
    Registered User
    Join Date
    08-11-2010
    Location
    Sweden
    MS-Off Ver
    Excel 2007
    Posts
    93

    Run a folder with xls fles and save as txt files

    Hello!

    I have a folder with +100 files in xls format that I need to change to .txt format and save with the same name in new folder!

    I did a macro for one file, but this needs to run for all the files in this folder! I need a script that can run thru all files and save them with extension ".txt"

    Thanks

    This is how my macro looks like:

        ChDir "C:\test\xls_files"
        Workbooks.Open Filename:="C:\test\xls_files\1.xls"
        ActiveWorkbook.SaveAs Filename:= _
            "C:\test\txt_files\1.txt", FileFormat:=xlText, _
            CreateBackup:=False
        ActiveWindow.Close

  2. #2
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Run a folder with xls fles and save as txt files

    Hi,

    Try this

    Sub Steffen()
    Dim strPath As String
    Dim i As Integer
    
    strPath = "C:\test\xls_files"
    
    With Application.FileSearch
        .LookIn = strPath
    
        For i = 1 To .FoundFiles.Count
               Workbooks.Open .FoundFiles(i)
               With ActiveWorkbook
                       .SaveAs Filename:= "C:\test\txt_files\1.txt", FileFormat:=xlText, CreateBackup:=False
                       .Close
               End with
        Next i
    End With
    end sub
    Please take time to read the forum rules

  3. #3
    Registered User
    Join Date
    08-11-2010
    Location
    Sweden
    MS-Off Ver
    Excel 2007
    Posts
    93

    Re: Run a folder with xls fles and save as txt files

    Did not work...
    The problem is that the filenames differ (from names to numbers or mixed) and I want them to keep the names..

    Thanks

  4. #4
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Run a folder with xls fles and save as txt files

    Where does it fail? Wich line?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1