I am new at VBA and I have tried to do some research on this topic but with no luck. I have a workbook with multiple sheets but I only want to save sheet 6 as a CSV file to a certain location without opening a new file. How would I go about that using VBA linked to something like a button? thanks
Asked
Active
Viewed 2,714 times
1
-
What do you mean by *"without opening a new file"*? You can use `Sheet6.SaveAs "foo.csv", xlCSV` but this will become your currently edited document and the old one will close. You want to keep the original workbook open dont you? – A.S.H Jul 03 '17 at 20:09
-
Yes I am trying to save the one sheet as a CSV file to upload to a database. But i am not wanting to close the original workbook. I dont want a book 2 to open as a CSV file. I want it to save under the same name but have like a - CSV – Bsmith Jul 03 '17 at 20:15
-
[This](https://stackoverflow.com/questions/44783923/excel-macro-multiple-sheets-to-csv/44792295#44792295) is applying to multi sheets. you can work well only one sheet. – Dy.Lee Jul 03 '17 at 22:20
1 Answers
2
Create a button and link it to this macro:
Sub Sheet6ToCSV()
Application.ScreenUpdating = False: Application.EnableEvents = False: Application.DisplayAlerts = False
On Error GoTo Cleanup
Dim fold As String: fold = "C:\SO\"
Dim fName As String: fName = "MySheet6"
Worksheets("Sheet6").Copy
With ActiveWorkbook
.SaveAs fold & fName
.Close False
End With
Cleanup:
Application.ScreenUpdating = True: Application.EnableEvents = True: Application.DisplayAlerts = True
End Sub

A.S.H
- 29,101
- 5
- 23
- 50