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

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
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,216,473
Messages
6,130,837
Members
449,597
Latest member
buikhanhsang

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