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!
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
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
 
Upvote 0

Forum statistics

Threads
1,214,839
Messages
6,121,887
Members
449,057
Latest member
Moo4247

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
Back
Top