Hello everyone,
I'm trying to write VBA function to check if file with name that contains some string exists.
Currently I have a code like that:
In sheet I'm using function like that: =IF(FileExists($B$3 &"\"& $B$2 &"\"& B4 &".txt");1;2)
I tried to upgrade my function by changing to to this version:
And in sheet I used it like that: =IF(FileExists($B$3;"\"&$B$2&"\";B4 &".tx");1;2)
The new version of my function is returning FALSE.
Table with initial data looks like that:
What I'm trying to get is to have function which will return TRUE(in third column) if in the folder that contains '123' in its name is a file that contains string from second column.
Could anyone asists me with that issue?
I'm trying to write VBA function to check if file with name that contains some string exists.
Currently I have a code like that:
VBA Code:
Function FileExists(path As String)
Dim fso_obj As Object
Dim full_path As String
Set fso_obj = CreateObject("Scripting.FileSystemObject")
FileExists = fso_obj.FileExists(path)
End Function
In sheet I'm using function like that: =IF(FileExists($B$3 &"\"& $B$2 &"\"& B4 &".txt");1;2)
I tried to upgrade my function by changing to to this version:
VBA Code:
Function FileExists(path As String, folder As String, file_name As String)
Dim fso_obj As Object
Dim full_path As String
full_path = path & "\" & folder & "*\*" & file & "*.*"
Set fso_obj = CreateObject("Scripting.FileSystemObject")
FileExists = fso_obj.FileExists(full_path)
End Function
And in sheet I used it like that: =IF(FileExists($B$3;"\"&$B$2&"\";B4 &".tx");1;2)
The new version of my function is returning FALSE.
Table with initial data looks like that:
Folder | 123 | |
Path | C:\Users\mmasiarek\Desktop | Exists |
File#1 | 1 | |
File#2 | 2 | |
File#3 | 3 |
What I'm trying to get is to have function which will return TRUE(in third column) if in the folder that contains '123' in its name is a file that contains string from second column.
Could anyone asists me with that issue?