返回列表 上一主題 發帖

[發問] 資料夾尋找文字檔案名稱問題尋問

  1. Option Explicit
  2. #If VBA7 Then
  3.   Private Declare PtrSafe Function PathIsDirectoryW Lib "shlwapi.dll" (ByVal pszPath As LongPtr) As Long
  4.   Private Declare PtrSafe Function PathFileExistsW Lib "shlwapi.dll" (ByVal pszPath As LongPtr) As Long
  5. #Else
  6.   Private Declare Function PathIsDirectoryW Lib "shlwapi.dll" (ByVal pszPath As Long) As Long
  7.   Private Declare Function PathFileExistsW Lib "shlwapi.dll" (ByVal pszPath As Long) As Long
  8. #End If

  9. '检测文件是否存在
  10. Public Function FileExists(ByVal strPath As String) As Boolean
  11.   strPath = strPath & String(5, vbNullChar)
  12.   If PathFileExistsW(StrPtr(strPath)) Then
  13.     FileExists = PathIsDirectoryW(StrPtr(strPath)) = 0
  14.   End If
  15. End Function

  16. Public Sub FilesExists()
  17.   Dim I As Long
  18.   For I = 1 To Range("A" & Rows.Count).End(xlUp).Row
  19.     Range("B" & I).Value = FileExists("\\89.80.70.1\design\add_word\" & Range("A" & I).Value & ".TXT")
  20.   Next I
  21. End Sub
複製代碼
世界那麼大,可我想去哪?

TOP

        靜思自在 : 【時間成就一切】時間可以造就人格,可以成就事業,也可以儲積功德。
返回列表 上一主題