EXCEL:我可以在函數中引用儲存格內的文字、檔案路徑嗎?

EXCEL:我可以在函數中引用儲存格內的文字、檔案路徑嗎?

我在 Excel 中有以下 VBA 模組,它允許我檢查給定資料夾中是否存在檔案:

Function FileExists(FilePath As String) As Boolean

'Declare variables
    Dim FileName As String

'Use the Dir function to get the file name
    FileName = Dir(FilePath)

'If file exists, return True else False
    If FileName <> "" Then FileExists = True _
    Else: FileExists = False

End Function

我的結果是這個函數輸出TRUEFALSE到一個單元格:

=FileExists("C:\folder\report.pdf")

我有一列包含要在該文件路徑中引用的名稱列表,因此結果是:

=FileExists("C:\folder\name\report.pdf")

我有辦法做到這一點嗎?我嘗試過使用INDIRECT&T函數,但無法讓函數轉義並正確讀取以輸出檔案路徑中的名稱。

相關內容