2016-05-31 87 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

相关问题