2016-05-31 82 views
1

我正在使用VBA自動創建文件夾。我需要創建的文件夾名稱之一包含字符č(c with caron)。當我在VBA中使用MkDir時,文件夾是用「c」而不是「č」創建的。VBA MkDir悄悄地刪除caron

示例代碼:

root_folder = "C:\customers\" 
folder_name = "háček" 'I do not think you can enter this into the VBA editor, but I am getting the folder_name from an external source 
full_folder_path = root_folder & folder_name & "\" 
MkDir full_folder_path 
attachment.SaveAs full_folder_path & attachment.filename 

這將創建一個文件夾,名爲 「C:\用戶\ HACEK \」,而不是 「C:\用戶\ HACEK \」,然後導致保存操作失敗,因爲它試圖保存在「C:\ customers \háček\」中,這當然不存在,VBA似乎能夠正確讀取和處理字符,因爲我可以從我的數據源中讀取它並將其保存爲文本文件沒有問題當涉及到創建文件夾似乎存在的問題

有沒有辦法讓VBA創建名稱,我已經指定的文件夾?


編輯:格式化

回答

1

如果使用FileSystemObject,您可以用正確的名稱創建文件夾:

Dim fs As Object 

Set fs = CreateObject("Scripting.FileSystemObject") 
fs.CreateFolder "C:\customers\hac" & ChrW(269) & "ek" 'ChrW(269) prints č 
+1

,完美的工作。非常感謝你。 – osf

相關問題