가 사용하는 UNC 경로는 악센트와 같은 비 ASCII 문자가 포함되어 있습니까 : 나는 실행 해요 코드의 일부는 여기에
입니까? 정확한 경로는 무엇입니까?
어쨌든 VBA의 파일 기능은 유니 코드와 잘 작동하지 않습니다.
당신은 동일을 달성하기 위해 FileSystemObject
를 사용하려고 할 수있는 좀 더 안정적으로보다 빌드에서 VBA 기능 :
Public Function FileExists(filePath as string) as Boolean
Dim o As Object
Set o = CreateObject("Scripting.FileSystemObject")
FileExists = o.FileExists(filePath)
End Function
는 Win32 API 그쪽을 사용하는 대신 32 비트 및 64 비트 환경에서 작동합니다
Private Const INVALID_FILE_ATTRIBUTES As Long = -1
#If VBA7 Then ' Win API Declarations for 32 and 64 bit versions of Office 2010 and later
Private Declare PtrSafe Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesW" (ByVal lpFileName As LongPtr) As Long
#Else ' WIN API Declarations for Office 2007
Private Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesW" (ByVal lpFileName As Long) As Long
#End If
Public Function FileExists(fname As Variant) As Boolean
If IsNull(fname) Or IsEmpty(fname) Then Exit Function
' Make sure that we can take care of paths longer than 260 characters
If Left$(fname, 2) = "\\" Then
FileExists = GetFileAttributes(StrPtr("\\?\UNC" & Mid$(fname, 2))) <> INVALID_FILE_ATTRIBUTES
Else
FileExists = GetFileAttributes(StrPtr("\\?\" & fname)) <> INVALID_FILE_ATTRIBUTES
End If
End Function
먼저 폴더에 수동으로 액세스하지 않고 실행하는 동안 오류가 발생하면 폴더에 액세스하는 데 권한 문제가 있습니다. – Alex
다음 링크에서 실행할 수 있는지 확인하십시오. http://allenbrowne.com/func-11.html 우리는 파일 경로를 가지고 놀아 라. ll. –
이것은 WebDAV 경로입니까? 이 유형의 경로로이 동작을 보았지만 깨끗한 솔루션은 없습니다. 파일이 있는지 확인하기 전에 VBA를 통해 해당 경로에서 Explorer를 열어 볼 수 있습니다. –