Excel宏从工作簿表单窗口弹出问题创建csv文件

时间:2013-06-24 06:54:07

标签: excel-vba-mac

将excel转换为csv文件时遇到问题。我的用例是编写一个宏来将每个工作簿表转换为csv文件并将它们压缩为单个文件。   所以我的代码是这样的       “OriginalWorkbook.Activate     '对于将每个表格转换为自己的CSV文件的表格数量

For Counter = SHCOUNT + 1 To Sheets.Count

     'Export as CSV to the root folder
     Set wks = ActiveWorkbook.Worksheets(Counter)
     wks.Copy 'to a new workbook
     Set newWks = ActiveSheet
     With newWks
        fileSaveName = Application.GetSaveAsFilename(newWks.Name, _
        fileFilter:="CSV Files (*.csv), *.csv")
        'ActiveWorkbook.SaveAs (fileSaveName)
        .SaveAs Filename:=fileSaveName, FileFormat:=xlCSV
        ZipNAme = newWks.Name
        If fileSaveName <> False Then
            'newWks.Delete
            'MsgBox "Save as " & fileSaveName
        End If

        .Parent.Close Savechanges:=False
    End With

    ''Add the created CSV file to the ZIP file
    Set oapp = CreateObject("Shell.Application")
    oapp.Namespace(FolderName).CopyHere fileSaveName

Next Counter

但是现在我面临着这个代码的问题,我在excel中有大约20张,每张表,windows saveas popup即将出现,我点击了20次保存以完成整个过程。

我对VB编码很新。任何人都可以帮我解决这个问题吗? 我必须在没有任何保存弹出的情况下继续进行,因为我事先给出了文件名。

谢谢, B1

1 个答案:

答案 0 :(得分:0)

    Sub exportcsv()
Dim ws As Worksheet
Dim path As String

path = ActiveWorkbook.path & "\" & Left(ActiveWorkbook.Name, InStr(ActiveWorkbook.Name, ".") - 1)
For Each ws In Worksheets
    ws.Copy
    ActiveWorkbook.SaveAs Filename:=path & "_" & ws.Name & ".csv", FileFormat:=xlCSV, CreateBackup:=False
    ActiveWorkbook.Close False
Next
End Sub

希望这会有所帮助,但不能保证它可能对您有用,但它可以替代让事情走上正轨。我自己也是VBA的新手:)