Solved

Saving Multiple Worksheets as Separate CSV Files to Specific Location

Posted on 2015-02-06
3
93 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:
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
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.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

911 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

23 Experts available now in Live!

Get 1:1 Help Now