im getting the following error message when i run this code that lets me make folders if they don't exist to save files in them: "run time error 75 path/file access error"
any thoughts?
Sub auto_organize_save1()
Dim fdObj As Object
Dim folder As String
Set fdObj = CreateObject("Scripting.FileSystemObject")
folderYear = "C:\temp\testing\" & Format(Now, "YYYY") & "\"
folderMonth = "C:\temp\testing\" & Format(Now, "YYYY") & "\" & Format(Now, "MM-MMM") & "\"
If Not fdObj.FolderExists(folder) Then
MkDir folderYear
End If
If Not fdObj.FolderExists(folder) Then
MkDir folderMonth
End If
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=folderMonth & "example.xlsx"
Application.DisplayAlerts = True
End Sub
CodePudding user response:
You check if folder
exists, not folderYear
and/or folderMonth
.
Try
If Not fdObj.FolderExists(folderYear) Then
MkDir folderYear
End If
If Not fdObj.FolderExists(folderMonth) Then
MkDir folderMonth
End If
Also, you might want to add in a check that the folder called testing exists.