简体   繁体   中英

Open and Save a New Workbook as CSV file (delimited)

I have a workbook that has about 30 sheets. Each sheet has it's own macro. Then, a sheet called "Main Page has macros. One of them Merges all sheets, creating a new sheet combined. I need another macro that when clicked, opens a NEW workbook, copies data from Sheet "Combined" and saves it as it's own Workbook, and also, name it "Tracking Import File (todays date) .CSV" (delimited) I can get it to do all of that except the Format of the CSV file is not the same as when I manually do it. Currently i have this macro doing this for another sheet as well, but that sheet gets saved as a normal workbook extension, which is working just fine. This is the code I have right now:

Set wb = Workbooks.Add
ThisWorkbook.Sheets("Back Order Follow up Report").Copy Before:=wb.Sheets(1)
wb.SAVEAS "S:\Production Department\Backorder Follow up reports\Back Order Follow up Report." & Format(Date, "MM.DD.YY") & ".xlsx"

*Set wb = Workbooks.Add
ThisWorkbook.Sheets("Combined").Copy Before:=wb.Sheets(1)
wb.SAVEAS "S:\Production Department\Tracking import\Tracking Import FileTEST." & Format(Date, "MM.DD.YY") & ".csv"*

End Sub

There is a second, optional parameter on the wb.SaveAs method that tells Excel what format to save the file in. Merely putting ".csv" at the end of a file doesn't make it a CSV, that's only a name. To save as a CSV use:

wb.SAVEAS "S:\Production Department\Tracking import\Tracking Import FileTEST." & Format(Date, "MM.DD.YY") & ".csv", xlCSV

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