我有以下功能,只能產生在Mac上一個運行時錯誤52(壞的文件名或號碼)就行了Open filePath & filename For Output As #1
運行時錯誤52錯誤的文件名 - 僅限Mac
Function ExportAsCSV(ByVal charToEncode As String, _
ByVal filePath As String, ByVal filename As String) As Boolean
'Function to Export string to CSV. Returns True/False if successful
'Tested and working on PC XL2003,2007 & 2010 // MAC XL2011
'On Error GoTo Err:
On Error GoTo 0
Open filePath & filename For Output As #1
Print #1, charToEncode
Close #1
ExportAsCSV = True
On Error GoTo 0
Exit Function
Err:
On Error GoTo 0
ExportAsCSV = False
End Function
例論點引起錯誤是:
filePath : "Untitled:Users:ooo:Desktop:New" : String
filename : ":FloridaRhum Barbancourt 5 Star Reserve Speciál 8 Years Old.csv" : String
這無疑導致一個問題,如果我將其更改爲文件名「:test.csv」,因爲它工作的例子。所有的單詞也工作正常,所以它似乎不是一個編碼問題,如果我生成一個長文件名相同的長度也很好。
我很難過..有什麼想法嗎?
編輯:
也只需添加的Open filePath & filename For Output As #1
實際上不會產生與在正確的位置正確的文件名的文件。但是因爲VBA產生錯誤,所以沒有寫入文件,因此文件是零字節。
特殊字符'á'顯現在那裏。你可以把它保存爲「:tásty.csv」嗎? – CuberChase
這是我檢查的第一件事。如果刪除整個單詞「Speciál」,它仍然不起作用。 – user3357963
你使用了多長的文件名?我剛做了一些快速測試,似乎有32個字符的限制,經過一番搜索似乎是一個錯誤? http://www.mrexcel.com/forum/excel-questions/518804-office-2011-mac-32-character-filename-limit.html#post2562411 – CuberChase