简体   繁体   中英

How to save a copy of current excel to CSV to new folder?

I am trying to save my current excel called Gaf to a CSV.

ActiveWorkbook.SaveAs Filename:=Workbooks(GAF).Sheets(Sheet1).Range("A2").Value & ".csv", FileFormat:=xlCSV

Any help?

Or.......

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

Technically works but not exactly a CSV FILE... I have tried putting in ".csv", xlCSV FileFormat:=xlCSV also gives me errors.

This is one of many codes to converting excel sheet to csv.

Sub test()
    Dim WB As Workbook, csvWB As Workbook
    Dim WS As Worksheet
    Dim myPath As String, myFn As String
    Dim vDB
    myPath = ThisWorkbook.Path & "\"
    myFn = myPath & "test.csv"

    Set WB = ActiveWorkbook
    Set WS = WB.ActiveSheet
    vDB = WS.UsedRange

    Set csvWB = Workbooks.Add(Template:=True)
    With csvWB
        Sheets(1).Range("a1").Resize(UBound(vDB, 1), UBound(vDB, 2)) = vDB
        .SaveAs myFn, xlCSV
        .Close (0)
    End With

    Set csvWB = Nothing


End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM