Save as .csv file

bujaman

Board Regular
Joined
Apr 2, 2009
Messages
56
I am trying to write a macro to save each worksheet as a separate .csv file. The file name of the csv file needs to come from cell Z1 of each worksheet, but I am running into some problems, what I think should work, isn't (which is the case in so many aspects of my life!). Here is what I have, any ideas?

Code:
[LEFT][COLOR=#000000]Sub SaveAsCSV()[/COLOR][/LEFT]

Dim FName As String    
Dim FPath As String         

FPath = "C:\Users\ben.griggs\Dropbox\BBP\Pricing Sheets\Converted [URL="http://www.xtremevbtalk.com/showthread.php?p=1395029#"][FONT=inherit]Database[/FONT][/URL] Pricing Tables\"    
FName = ActiveSheet.Range("Z1").Text   
   
ActiveWorkbook.SaveAs Filename:=FPath & FName & ".csv", FileFormat:=xlCSVMSDOS

 [LEFT][COLOR=#000000]End Sub[/COLOR][/LEFT]


Thanks!
 

Some videos you may like

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,779
Office Version
  1. 2010
Platform
  1. Windows
Maybe ...

Code:
Sub SaveAsCSV()
    Const sPath     As String = "C:\Users\ben.griggs\Dropbox\BBP\Pricing Sheets\Converted Database Pricing Tables\"
    Dim wks         As Worksheet
    Dim sFile       As String

    For Each wks In Worksheets
        wks.Select
        sFile = Range("Z1").Text & ".csv"
        ActiveWorkbook.SaveAs Filename:=sPath & sFile, _
                              FileFormat:=xlCSVMSDOS
    Next wks
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,655
Messages
5,597,384
Members
414,141
Latest member
Joey_T92

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top