Convert from XLS to CSV using VBScript

Discussion in 'Visual Basic ( VB )' started by wiere, Jun 25, 2009.

  1. wiere

    wiere New Member

    Joined:
    Jun 25, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Realised used this site quite a lot without ever giving back to it, so i thought i'd change that.

    This script is nice and simple way of converting xls to csv simply drag the files onto the vbs to use.

    Code:
    Set objArgs = WScript.Arguments
    For I = 0 to objArgs.Count - 1
    
        FullName = objArgs(I)
        FileName = Left(objArgs(I), InstrRev(objArgs(I), ".") )
    
        Set objExcel = CreateObject("Excel.application")
        set objExcelBook = objExcel.Workbooks.Open(FullName)
    
        objExcel.application.visible=false
        objExcel.application.displayalerts=false
    
        objExcelBook.SaveAs FileName & "csv", 23
    
        objExcel.Application.Quit
        objExcel.Quit   
    
        Set objExcel = Nothing
        set objExcelBook = Nothing
    
    Next
    
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    How do I drag the files to VBS.
     
  3. wiere

    wiere New Member

    Joined:
    Jun 25, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Sorry i didnt explain. Save this vbs script and drag the XLS files onto it in windows explorer.
     
  4. wiere

    wiere New Member

    Joined:
    Jun 25, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    I'm sorry i missed the top line of code out. This needs to be the first line:

    Code:
     Set objArgs = WScript.Arguments
    should work now
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Added the first line to the code above.
     
  6. Click_talk

    Click_talk New Member

    Joined:
    Jul 8, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    How to make it to work for Multiple Tabl in the same Excel file.

    PLease help.

    Thanks,
    James
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice