Bsmith
Bsmith

Reputation: 25

Saving Single Sheet as CSV File

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

Upvotes: 1

Views: 3008

Answers (1)

A.S.H
A.S.H

Reputation: 29332

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

Upvotes: 2

Related Questions