VBA Saving a file using a filename as a specified cell and as a CSV file

khouston

New Member
Joined
Jan 24, 2014
Messages
9
Hi
i am trying to create a macro that will automatically save a sheet as a CSV sheet with the filename as a concatenated cell name within another sheet if that makes sense.
this is what i have so far.

sfilename = Sheets("dealer input").Range("i1").Value

Sheets("CSV").Select.SaveAs Filename:= _
"X:\Applications\1-Inbound\sfilename.csv", FileFormat:=xlCSV, _
CreateBackup:=False

End Sub

but all this is doing is saving the file as sfilename
any help will be greatly appreciated
thanks
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Try

Sheets("CSV").Select.SaveAs Filename:= _
"X:\Applications\1-Inbound\" & sfilename & ".csv", FileFormat:=xlCSV, _
CreateBackup:=False
 
Upvote 0
Hi Emma

thanks for that.
it is still coming up with a Debug error on the file location

"X:\Applications\1-Inbound\" & sfilename & ".csv", FileFormat:=xlCSV, CreateBackup:=False

its not liking this part for some reason.
 
Upvote 0
Sorry, didn't look at your code properly - I think the problem might be with trying to apply SaveAs to a single worksheet.
 
Upvote 0
Hi,
see if this helps:

Code:
     Sheets("CSV").Copy
    With ActiveWorkbook
        .SaveAs Filename:= _
                "X:\Applications\1-Inbound\" & sfilename & ".csv", _
                FileFormat:=xlCSV, _
                CreateBackup:=False
        .Close False
    End With

Dave
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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