VBA to save as CSV not changing file format

Vispon

New Member
Joined
Jul 12, 2010
Messages
20
Hi Everyone

I have been using the below code (kindly suggested by someone on this forum) at the end of my vba to save the file as a csv with a custom filename. It doesn't seem to be actually changing the format of the file though.

The file extension shows csv however if I try to open the created file I get an error saying 'the file format and extension of [file name] do not match.

Code:
TMS845Sub savedi()
myfilename = "INV_TRC_" & Range("c1") & "_" & Format(Now(), "DDMMYYYYHHMMSS")
Filename = Application.GetSaveAsFilename(InitialFileName:=myfilename, fileFilter:="csv Files (*.csv), *.csv")
ActiveWorkbook.SaveAs Filename:=Filename


End Sub

Any suggestions on what needs to be changed?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
You are forgetting the File Format argument of your SaveAs command. Otherwise, you are just saving it as an Excel file. Changing the name alone doesn't do it, you can actually name an Excel with any extension you want.
So that line should look like:
Code:
ActiveWorkbook.SaveAs Filename:=Filename[COLOR=#ff0000], FileFormat:=xlCSV[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,215,008
Messages
6,122,672
Members
449,091
Latest member
peppernaut

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