Solved

Saving Multiple Worksheets as Separate CSV Files to Specific Location

Posted on 2015-02-06
3
96 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
Simon earned 500 total points
ID: 40594162
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
ID: 40594194
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
ID: 40594221
It is actually working now.  Sorry.  Your code is correct, just have to add the ".  

Thank you!!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

730 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