Pinaceous
Well-known Member
- Joined
- Jun 11, 2014
- Messages
- 1,124
- Office Version
- 365
- Platform
- Windows
Hi All,
I'm working with
where I have my code produce a Main Folder based off of its workbooks sheet cell value as its name.
Now, I would like to create a subfolders to put inside this Main Folder in using FSO.
So, far I have as follows:
I'm getting an error with this line
.
Can someone help me?
Thanks!
pinaceous
I'm working with
VBA Code:
FSO = CreateObject("Scripting.FileSystemObject")
Now, I would like to create a subfolders to put inside this Main Folder in using FSO.
So, far I have as follows:
VBA Code:
Sub CreateFolders()
Dim FSO As Object, sourceFolder As Object, file As Object
Dim sPath As String, sMain As String, sFolder As String
Dim i As Long
Set FSO = CreateObject("Scripting.FileSystemObject")
sPath = CreateObject("WScript.Shell").SpecialFolders("Desktop")
sMain = sPath & "\" & ThisWorkbook.Sheets(1).Range("B11").Value
If Dir(sMain, vbDirectory) <> "" Then 'if the folder exists
'Do nothing
MsgBox "Duplicate Folder!"
'MsgBox Application.UserName & "Duplicate Folder!"
'MsgBox Environ("Temp") & " Hello!"
Exit Sub
Else ' 'if the folder not exists
MkDir sMain
FSO.MoveFile Source:="C:\Users\Desktop\" & Sheets(1).Range("E25").Value, Destination:=sMain & "\" & Sheets(1).Range("E25").Value
'FSO.MoveFile Source:="C:\Users\Desktop\" & Sheets(1).Range("E31").Value, Destination:=sMain & "\" & Sheets(1).Range("E31").Value
'FSO.MoveFile Source:="C:\Users\Desktop\" & Sheets(1).Range("E37").Value, Destination:=sMain & "\" & Sheets(1).Range("E37").Value
End If
Set FSO = Nothing
For i = 11 To 23
sFolder = sMain & "\" & Sheets(1).Range("C" & i).Value
If Dir(sFolder) = "" Then
MkDir sFolder
End If
Next
End Sub
I'm getting an error with this line
VBA Code:
FSO.CreateFolder "FSO.MoveFile Source:="C:\Users\Desktop\" & Sheets(1).Range("E25").Value, Destination:=sMain & "\" & Sheets(1).Range("E25").Value
Can someone help me?
Thanks!
pinaceous
Last edited: