Hi All
I've found this code and it's working fine.
The function get the last recent (newest) file from a specified folder with a search string.
Everything is working fine, but:
if a folder contains special character (German, ä, ö, or ü) I get an exception "folder not found" while
setting > Set SourceFolder = FSO.GetFolder(strSourceFolderName)
Any idea how i can set another character code to get work this code?
Thanks
Bruno
<<snipped>>
Function getFileName(strSourceFolderName As String, strSearchText As String) As String
Dim FSO As Scripting.FileSystemObject
Dim SourceFolder As Scripting.Folder
Dim dict As Scripting.Dictionary
Set dict = CreateObject("Scripting.Dictionary")
Dim iArray()
Dim sfil As String
Dim par As String
Dim bGotFile As Boolean
bGotFile = False
Set FSO = New Scripting.FileSystemObject
Set SourceFolder = FSO.GetFolder(strSourceFolderName)
sfil = Dir(strSourceFolderName & "\" & "*.xls*")
Do Until sfil = ""
If InStr(sfil, strSearchText) > 0 Then
dict.Add CDbl(SourceFolder.Files(sfil).DateCreated), sfil
bGotFile = True
End If
sfil = Dir$
Loop
If bGotFile Then
iArray() = dict.Keys
getFileName = CStr(dict.Item(WorksheetFunction.Max(iArray())))
Else
getFileName = "NO-FILE"
End If
Set SourceFolder = Nothing
Set FSO = Nothing
End Function
I've found this code and it's working fine.
The function get the last recent (newest) file from a specified folder with a search string.
Everything is working fine, but:
if a folder contains special character (German, ä, ö, or ü) I get an exception "folder not found" while
setting > Set SourceFolder = FSO.GetFolder(strSourceFolderName)
Any idea how i can set another character code to get work this code?
Thanks
Bruno
<<snipped>>
Function getFileName(strSourceFolderName As String, strSearchText As String) As String
Dim FSO As Scripting.FileSystemObject
Dim SourceFolder As Scripting.Folder
Dim dict As Scripting.Dictionary
Set dict = CreateObject("Scripting.Dictionary")
Dim iArray()
Dim sfil As String
Dim par As String
Dim bGotFile As Boolean
bGotFile = False
Set FSO = New Scripting.FileSystemObject
Set SourceFolder = FSO.GetFolder(strSourceFolderName)
sfil = Dir(strSourceFolderName & "\" & "*.xls*")
Do Until sfil = ""
If InStr(sfil, strSearchText) > 0 Then
dict.Add CDbl(SourceFolder.Files(sfil).DateCreated), sfil
bGotFile = True
End If
sfil = Dir$
Loop
If bGotFile Then
iArray() = dict.Keys
getFileName = CStr(dict.Item(WorksheetFunction.Max(iArray())))
Else
getFileName = "NO-FILE"
End If
Set SourceFolder = Nothing
Set FSO = Nothing
End Function