FileSystemObject.GetFile无法处理文件名中带有单引号或撇号的文件?

时间:2012-01-15 01:34:45

标签: vba excel-vba excel

FileSystemObject.GetFile()如果在带有单引号/撇号的文件名上调用它,则会收到“找不到文件”错误,即:

FileSystemObject.GetFile("D:\somepath\some file with an ' apostrophe in it.txt")

这是我正在尝试的事情:

Public Sub VBA_GetFileInfo(FileName As String, ByRef outDateCreated As Date, ByRef outDateAccessed As Date, ByRef outDateModified As Date, ByRef outFileSize As Long)

Dim tmpFile As String
'SOME THINGS I'VE TRIED TO OVERCOME THE PROBLEM, WITH NO SUCCESS:
'tmpFile = """" & FileName & """"
'tmpFile = FileName
'tmpFile = Replace(tmpFile, "\", "\\")
'tmpFile = Replace(tmpFile, "'", "\'")


Dim fso As FileSystemObject
Dim f As file
Dim s As String
Set fso = New FileSystemObject
----> BLOWS UP HERE with "file not found" error:
Set f = fso.GetFile(tmpFile)

1 个答案:

答案 0 :(得分:0)

brettdj的评论:

  

因为这应该没问题,你确定它是撇号 - 它可能是一个   `而不是'

...原来是正确的答案,它必须是撇号而不是单引号导致错误。