Check if a path/folder is available

Viewed 36

Using VBA at Excel, I save data of a table at a ".dat" file, at a network folder. How can check if the folder is available? My idea would be if folder A is not available, save the file at folder B Something like

if {{ "\\PC2\Shared" is not available }} then then nA = "D:\data.dat" else nA = "\\PC2\Shared\data.dat"
1 Answers

You can use the FileSystemObject to check if a folder exists.

Const FolderA As String = "\\Some path"
Const FolderB As String = "\\Some path"

Dim folderPath As String

With CreateObject("Scripting.FileSystemObject")
    If .FolderExists(FolderA) Then folderPath = FolderA Else folderPath = FolderB
End With

'use folderPath to append the file name and save
Related