excel 根据标签颜色将多个标签提取到多个平面文件中

qmb5sa22  于 2022-11-26  发布在  其他
关注(0)|答案(1)|浏览(134)

我正在尝试导出我的excel工作簿中的标签,这些标签是绿色的,并转换为csv文件。任何指针都将非常感谢。

kxe2p93d

kxe2p93d1#

导出到CSV

基本

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

相关问题