2011-01-13 85 views
0

How can I install/use 「Scripting.FileSystemObject」 in Excel 2011 for MAC?的回答似乎表明,在Excel 2010中爲Mac使用Scripting.FileSystemObject可能。在Excel 2011 VBA for Mac中是否有替代Scripting.FileSystemObject?

什麼其他替代可用,因此我可以:

  • 通過每個文件中的每個工作表中獲取所有Excel文件的集合在特定目錄
  • 迭代並將其導出到a .csv文件

當前這是爲每個文件六個步驟過程:

--how to create CSV files for all worksheets in a file: 
1. open file 
2. click "Developer" 
3. click editor 
4. click ThisWorkbook 
5. copy in: 
Sub save_all_csv() 
    On Error Resume Next 
    Dim ExcelFileName As String 
    ExcelFileName = ThisWorkbook.Name 
    For Each objWorksheet In ThisWorkbook.Worksheets 
     Filename = "FILE-" & ExcelFileName & "-WORKSHEET-" & objWorksheet.Name & ".csv" 
     objWorksheet.SaveAs Filename:="Macintosh HD:Users:edward:Documents:temporaryNoBackup:" & Filename, FileFormat:=xlCSV, CreateBackup:=False 
    Next 
    Application.DisplayAlerts = False 
    Application.Quit 
End Sub 
6. click run (it closes by itself) 

我正在尋找一種方式來自動這在Mac上,理想情況下,(?cron作業?服務)將打開excel文件每10分鐘一次,然後依次查看目錄,將所有其他Excel文件轉換爲.csv文件,然後自行關閉。

沒有Scripting.FileSystemObject的,我怎樣才能使這個Excel到CSV轉換Mac上的全自動的嗎?

回答

1

我能想到的唯一方法是使用「目錄」功能。由於mac支持文件名中的額外字符,通配符不能與「Dir」函數一起使用。這是一個示例。

Function GetFileList(folderPath As String) As Collection 
'mac vba does not support wildcards in DIR function 

    Dim file As String 
    Dim returnCollection As New Collection 

    If Right$(folderPath, 1) <> "\" Then 
     folderPath = folderPath & "\" 
    End If 

    file = Dir$(folderPath) 'setup initial file 

    Do While Len(file) 
     returnCollection.Add folderPath & file 
     file = Dir$ 
    Loop 

    Set GetFileList = returnCollection 
End Function 
相關問題