Results 1 to 9 of 9

Convert all .txt files to .xls in folder

Threaded View

  1. #1
    Registered User
    Join Date
    10-18-2011
    Location
    Redondo Beach, CA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Convert all .txt files to .xls in folder

    Hi all,

    I'm trying to write a VBA macro that opens all .txt files in a folder and saves them as .xls with the same name. I've found some code online that has some of the same functionality but they use Application.Filesearch which is no longer available on Excel 2010.

    I found an example using the Dir function but am having trouble getting it to work.

    Thanks for any help you can offer.


    Sub LoopAllFiles()
    
    sPath = "S:\Test loop macro\files"
    
    sDir = Dir$(sPath & "*.txt", vbNormal)
    
    Do Until LenB(sDir) = 0
    
    Set oWB = Workbooks.Open(sPath & sDir)
    
        ActiveWorkbook.SaveAs , FileFormat:= _
            xlOpenXMLWorkbook, CreateBackup:=False
    
    oWB.Close
    
    sDir = Dir$
    
    Loop
    End Sub
    Last edited by natalie1230; 10-18-2011 at 02:46 PM.

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