Saving file as .csv VBA

sh1ne

New Member
Joined
Jul 3, 2017
Messages
29
Hello,

got problem, can somebody help me? How can I save file as .csv by macro in current folder? I would like to avoid defining file path to save because it will be different in every case.

Another question - how can I grab string from cell(A1) and put it in the name of saved workbook as prefix?

Thanks.
 

Some videos you may like

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
53,437
Office Version
365
Platform
Windows
ActiveWorkbook.Path will return the path that the current file is in.

If you turn on your Macro Recorder, and record yourself saving as a "CSV", you will have the VBA code that you need for that.

So here is an example of saving the file to the current directory as a CSV file, using cell A1 as the file name:
Code:
    Dim fName As String
    fName = ActiveWorkbook.Path & "\" & Range("A1") & ".csv"
    ActiveWorkbook.SaveAs Filename:=fName, _
        FileFormat:=xlCSV, CreateBackup:=False
 

Watch MrExcel Video

Forum statistics

Threads
1,099,364
Messages
5,468,189
Members
406,570
Latest member
Ktvu2006

This Week's Hot Topics

Top