SpaaamCatcher
Technical User
Hi, there. I want to programmatically create a folder path that has been defined in a particular cell in Excel, and it works, but not all the way.
If the user enters a value in cell A1 equal to: "C:\Folder1\Folder2", I want to check if this path exists and then create it if it doesn't. This works, but only if I'm only creating the last folder...
So if A1 = "C:\Folder1\Folder2" and Folder1 exists, the code will generate Folder2. HOWEVER, if Folder1 does NOT exist, I get a path not found error and nothing gets created. Whassup???
Help?
Jamie
See code below:
Private Sub DirectoryExists()
Dim Msg, Style, Title, Response
Dim strFolderName As String
strFolderName = Worksheets("Test1"
.Range("A1"
Set FSO = CreateObject("Scripting.FileSystemObject"
If Not FSO.FolderExists(strFolderName) Then
Msg = "This folder does not exist. Would you like to create it?"
Style = vbYesNoCancel
Title = "Create Folder?"
Response = MsgBox(Msg, Style, Title)
If Response <> vbYes Then End
Set CreatedFolder = FSO.CreateFolder(strFolderName)
End If
End Sub
If the user enters a value in cell A1 equal to: "C:\Folder1\Folder2", I want to check if this path exists and then create it if it doesn't. This works, but only if I'm only creating the last folder...
So if A1 = "C:\Folder1\Folder2" and Folder1 exists, the code will generate Folder2. HOWEVER, if Folder1 does NOT exist, I get a path not found error and nothing gets created. Whassup???
Help?
Jamie
See code below:
Private Sub DirectoryExists()
Dim Msg, Style, Title, Response
Dim strFolderName As String
strFolderName = Worksheets("Test1"
Set FSO = CreateObject("Scripting.FileSystemObject"
If Not FSO.FolderExists(strFolderName) Then
Msg = "This folder does not exist. Would you like to create it?"
Style = vbYesNoCancel
Title = "Create Folder?"
Response = MsgBox(Msg, Style, Title)
If Response <> vbYes Then End
Set CreatedFolder = FSO.CreateFolder(strFolderName)
End If
End Sub