Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6973471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:06:45+00:00 2026-05-27T17:06:45+00:00

I need to programmaticaly via a VBA/VBS script export all worksheets (4 in total

  • 0

I need to programmaticaly via a VBA/VBS script export all worksheets (4 in total and I know the names) to worksheet named csv files in the same folder, without loading excel and running the macro manually.

Ideally the script would take in the source filepath/filename.xls and the export filepath as command line arguments.

I have read many Excel VBA scripts for doing just that within Excel and I have seen some for loading an excel workbook to export the first sheet. However when I try to blend the two I get this error:

(1,12) Expected End of Statement

Dim source As Workbook
Set source = Application.Workbooks.Open(WScript.Arguments.Item(0), ReadOnly:=True)
For Each sheet In source.Sheets
.SaveAs Filename:= WScript.Arguments.Item(1) & Source.Sheets.Name, FileFormat:=xlCSV
Next sheet
wb.Close
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:06:45+00:00Added an answer on May 27, 2026 at 5:06 pm

    A vbs to run this code would look something like this.

    1. The vbs file can be executed from the commandline
    2. The folder name is redundant as if the file exists (the FSO object tests for this) then the folder it resides in must also exist
    3. The code automates Excel to separate the sheets

    two key points to note compared to your VBA above

    • you can’t Dim a vbs object as a string, Workbook etc (hence your initial error). You can only Dim them
    • you can’t used a named constant such as xlCSV in vbscript, hence the use of 6 below as the CSV format

      Dim strFilename  
      Dim objFSO  
      Set objFSO = CreateObject("scripting.filesystemobject")  
      strFilename = "C:\temp\test.xlsx"  
      If objFSO.fileexists(strFilename) Then  
        Call Writefile(strFilename)  
      Else  
        wscript.echo "no such file!"  
      End If  
      Set objFSO = Nothing  
      
      Sub Writefile(ByVal strFilename)  
      Dim objExcel  
      Dim objWB  
      Dim objws  
      
      Set objExcel = CreateObject("Excel.Application")  
      Set objWB = objExcel.Workbooks.Open(strFilename)  
      
      For Each objws In objWB.Sheets  
        objws.Copy  
        objExcel.ActiveWorkbook.SaveAs objWB.Path & "\" & objws.Name & ".csv", 6  
        objExcel.ActiveWorkbook.Close False  
      Next 
      
      objWB.Close False  
      objExcel.Quit  
      Set objExcel = Nothing  
      End Sub  
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably a very strange request. I need to programmaticaly (via code) change
I'm using xmlhttp via vba in excel 2010. I need to programmatically add an
I have a Zimbra installation and I need to programmaticaly update contacts in it.
I would really need to programmatically click on all nodes in the collection, but
I have a C code base and need to programmatically identify all of the
I need a way to programmaticaly delete documents from Sharepoint 2007 document library. I
I need to write a program that imports payments taken via amazon for items
When creating Active Directory users from a script, I also need to set the
For a Greasemonkey script running on twitter.com, I need to access the twttr.streams.TweetStream instance
I need to programmatically solve a system of linear equations in C, Objective C,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.