Sub ExportToCSV()
Const DST_PATH As String = "C:\Test"
Dim wb As Workbook: Set wb = ThisWorkbook ' workbook containing this code
Application.ScreenUpdating = False
Dim sws As Worksheet
Dim dwb As Workbook
Dim dFilePath As String
For Each sws In wb.Worksheets
If sws.Tab.Color = vbGreen Then
sws.Copy ' creates a new single-worksheet workbook
Set dwb = Workbooks(Workbooks.Count)
dFilePath = DST_PATH & Application.PathSeparator & sws.Name & ".csv"
Application.DisplayAlerts = False ' overwrite without confirmation
dwb.SaveAs Filename:=dFilePath, FileFormat:=xlCSV ' xlCSVUTF8
Application.DisplayAlerts = True
dwb.Close SaveChanges:=False
End If
Next sws
Application.ScreenUpdating = True
MsgBox "Worksheets exported.", vbInformation
End Sub
1条答案
按热度按时间kxe2p93d1#
导出到CSV
基本