检查路径/文件夹是否可用



使用Excel中的VBA,我将表的数据保存在"中;。dat";文件,位于网络文件夹中。如何检查文件夹是否可用?我的想法是,如果文件夹A不可用,请将文件保存在文件夹B类似的东西

if {{ "\PC2Shared" is not available }} then then nA = "D:data.dat" else nA = "\PC2Shareddata.dat"

您可以使用FileSystemObject来检查文件夹是否存在。

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

相关内容

最新更新