M Darblade
M Darblade

Reputation: 333

VBA Export sheet as a csv without losing focus of my current workbook

I would like to export a sheet as a csv into a new dir but it doesn't work using the SaveAs method of the worksheet.

When I use SaveAs, I "lose focus" of my current workbook and the current workbook is now the csv file (in the new dir). I would like to export the sheet and keep the focus on the current workbook.

Upvotes: 0

Views: 1828

Answers (1)

Jeanno
Jeanno

Reputation: 2859

This will work for you

Sub SaveCSV()
    Sheet1.Copy ' Change to whatever sheet you want to copy
    ActiveWorkbook.SaveAs "MyFileCSV.csv", xlCSV
    ActiveWorkbook.Close False
    ThisWorkbook.Activate
End Sub

Upvotes: 3

Related Questions