If you're accepting user input for folder paths, you might need to check for trailing backslashes (\
) before building a file path. The FSO.BuildPath
method makes this simpler:
Const sourceFilePath As String = "C:\Temp" '<-- Without trailing backslash
Const targetFilePath As String = "C:\Temp\" '<-- With trailing backslash
Const fileName As String = "Results.txt"
Dim FSO As FileSystemObject
Set FSO = New FileSystemObject
Debug.Print FSO.BuildPath(sourceFilePath, fileName)
Debug.Print FSO.BuildPath(targetFilePath, fileName)
Output:
C:\Temp\Results.txt
C:\Temp\Results.txt