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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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,641
Messages
6,120,684
Members
448,977
Latest member
dbonilla0331

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