Save as CSV (modifying SAVE.AS)

GarettJay

New Member
Joined
Jul 2, 2017
Messages
6
I have the following formula.
It works for saving as a new workbook. How can I get it to work for saving as CSV?


I have tried adding ".csv", FileFormat:=xlCSV to it but no such luck thus far.


Cheers :)




Code:
 ActiveWorkbook.SaveAs Filename:="C:\User\Test.CSV" & Test1Str & " " & TestStr & " " & ActiveWorkbook.Name
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Make sure that you provide a proper path and filename, along with the fileformat, for example...

Code:
ActiveWorkbook.SaveAs Filename:="C:\User\Domenic\Documents\sample.csv", FileFormat:=xlCSV
 
Last edited:
Upvote 0
Thanks. That worked. Here's a problem with this method however. It assumes you have saved the original excel. In one excel I have highlighted changes. I close that without saving and then the new excel keeps those changes. When I do this with a CSV. It keeps the original without macro changes of the original document. Any way to get around that?
 
Upvote 0
Hmmmmmm When you insert a table and highlight data, the excel does not like it in CSV format and pretends it does not exist. Wonder how to get around this issue
 
Upvote 0
A CSV file is a text file, so it will not store tables or formatting.
 
Upvote 0
True. I don't suppose you'd be able to save that
Code:
[COLOR=#333333]ActiveWorkbook.SaveAs Filename:="C:\User\Domenic\Documents\sample.csv", FileFormat:=xlCSV
[/COLOR]as a variable? Cheers
 
Upvote 0
Save what as a variable?
 
Upvote 0
Oh sorry. I mean as in if you are working with multiple excels at once, won't .activeworkbook be liable to give you errors as it will get confused on which activeworkbook to save? How would I rearrange that to include workbook and sheet names. E.g Workbook S7 Sheet 1. I suppose that would mean I'd need a macro per excel though. I guess if its more reliable thats not an issue
 
Upvote 0
When you open your target workbook, you can assign it to a variable, and then use that variable to save it...

Code:
[FONT=Verdana]    [COLOR=darkblue]Dim[/COLOR] wkb [COLOR=darkblue]As[/COLOR] Workbook
    
    [COLOR=darkblue]Set[/COLOR] wkb = Workbooks.Open("c:\users\domenic\desktop\book2.xlsx")

    [COLOR=#008000]'etc
    '
    '[/COLOR]
    
    wkb.SaveAs Filename:="[FONT=Verdana]c:\users\domenic\desktop\[/FONT]sample.csv", FileFormat:=xlCSV[/FONT]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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