Results 1 to 2 of 2

Thread: convert multiple excel spreadsheets to csv

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2010
    Posts
    41

    convert multiple excel spreadsheets to csv

    Can someone please give a hint on how to convert multiple excel worksheets from a single excel workbook.

    I have a piece of code that will convert the first worksheet in the workbook but no more than that:

    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
    Is it possible to do more than one worksheet?

    Any help on this would be greatly appreciated.

  2. #2
    Addicted Member
    Join Date
    Jul 2009
    Posts
    208

    Re: convert multiple excel spreadsheets to csv

    Try something like this (untested):
    Code:
    For Each objWorksheet In objExcelBook.Worksheets
      objWorksheet.Copy
      objExcel.ActiveWorkbook.SaveAs "theFileName.csv", 23
      objExcel.ActiveWorkbook.Close False
    Next
    Change "theFileName.csv" to the required file name, maybe including the sheet name.

Posting Permissions

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



Click Here to Expand Forum to Full Width