I have a question that is very similar to some others i have seen on here, but they dont quite answer what i need, or when i have tried them it has caused an error that i dont know how to solve. Only being level 5 i can't comment to ask a question.
In excel i have a file that is used for the naming profile for quotation folders.
I have tried to use the answer for: Create a folder and sub folder in Excel VBA and tweaked it as per the below, but it errors when it gets to If Functions.FolderExists(path) Then
it says
Run-time error '424': Object required.
I also need to to create the folder name as per sheet "Data Entry" cell "C44" and "C31", i then need to add subfolders to this which are not referenced in any cell including: 1. Customer RFQ This will have a further subfolder with the name base on "Data Entry" cell "C33"
- Design Engineering
- Drawings
- Costings
- Schedules
- Quotation
Any help would be greatly appreciated. Thank you,
'requires reference to Microsoft Scripting Runtime
Sub MakeFolder()
Dim strFolder As String, strPath As String
strFolder = CleanName(Range("C31")) ' assumes folder name is in C31
strPath = Range("C44") ' assumes path name is in C44
If Not FolderExists(strPath) Then
'Path doesn't exist, so create full path
FolderCreate strPath & "\" & strFolder
Else
'Path does exist, but no quote folder
If Not FolderExists(strPath & "\" & strFolder) Then
FolderCreate strPath & "\" & strFolder
End If
End If
End Sub
Function FolderCreate(ByVal path As String) As Boolean
FolderCreate = True
Dim fso As New FileSystemObject
If Functions.FolderExists(path) Then 'This is the part that doesn't work
Exit Function
Else
On Error GoTo DeadInTheWater
fso.CreateFolder path ' could there be any error with this, like if the path is really screwed up?
Exit Function
End If
DeadInTheWater:
MsgBox "A folder could not be created for the following path: " & path & ". Check the path name and try again."
FolderCreate = False
Exit Function
End Function
Function FolderExists(ByVal path As String) As Boolean
FolderExists = False
Dim fso As New FileSystemObject
If fso.FolderExists(path) Then FolderExists = True
End Function
Function CleanName(strName As String) As String
'will clean part # name so it can be made into valid folder name
'may need to add more lines to get rid of other characters
CleanName = Replace(strName, "/", "")
CleanName = Replace(CleanName, "*", "")
End Function
Any help greatly appreciated. Thank you