Solved

Saving Multiple Worksheets as Separate CSV Files to Specific Location

Posted on 2015-02-06
3
92 Views
Last Modified: 2016-02-10
The current code I have is working, however how do I add a specific location that I want the csv files saved to?

The location is "H:\Touchstone"

Sub SAVEASCSV()
Dim ws As Worksheet, newWb As Workbook
Application.ScreenUpdating = False
For Each ws In Sheets(Array("CONTRACT", "LOC", "REINS"))
   ws.Copy
   Set newWb = ActiveWorkbook
   With newWb
      .SAVEAS ws.Name, xlCSV
            .Close (False)
   End With
Next ws
Application.ScreenUpdating = True

End Sub

Open in new window

0
Comment
Question by:kateebebe
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
SimonAdept earned 500 total points
Comment Utility
Sub SAVEASCSV()
Dim ws As Worksheet, newWb As Workbook, savePath as string
savePath=H:\Touchstone\" 'Variable to store the path to the folder you want to save files in.
Application.ScreenUpdating = False
For Each ws In Sheets(Array("CONTRACT", "LOC", "REINS"))
   ws.Copy
   Set newWb = ActiveWorkbook
   With newWb
      .SAVEAS savePath & ws.Name, xlCSV 'Concatenate the path and workbook name
       .Close (False)
   End With
Next ws
Application.ScreenUpdating = True

End Sub

Open in new window

0
 

Author Comment

by:kateebebe
Comment Utility
That didn't work.  It continues to save in the last place I did a save as csv, but now it renames the saved files as H:\touchstoneContract.csv

ps.  There is a " missing right after the savepath above in your code.
0
 

Author Comment

by:kateebebe
Comment Utility
It is actually working now.  Sorry.  Your code is correct, just have to add the ".  

Thank you!!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now