How To Create or Get a folder using FSO (File System Object) in VBA
Sub GetOrCreateFolder()
Dim objFSO As Object
Dim strFolderPath As String
Dim strFldr As String
On Error GoTo ehand
strFolderPath = ThisWorkbook.Path & "\SavedFiles"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists(strFolderPath) Then
objFSO.CreateFolder strFolderPath
Else
objFSO.GetFolder strFolderPath
End If
ehand:
If Err <> 0 Then
MsgBox Err.Number & vbCrLf & Err.Description
End If
End Sub
Sub GetOrCreateFolder()
Dim objFSO As Object
Dim strFolderPath As String
Dim strFldr As String
On Error GoTo ehand
strFolderPath = ThisWorkbook.Path & "\SavedFiles"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists(strFolderPath) Then
objFSO.CreateFolder strFolderPath
Else
objFSO.GetFolder strFolderPath
End If
ehand:
If Err <> 0 Then
MsgBox Err.Number & vbCrLf & Err.Description
End If
End Sub
No comments:
Post a Comment