jdluke6545
Board Regular
- Joined
- Jul 30, 2021
- Messages
- 53
- Office Version
- 2019
- Platform
- Windows
I am using this code, which is working perfectly:
Which looks to see if the folder "mm-yyyy" exists in "C:\Users\JD\Documents\Completed Time Sheets\" and if not it creates the folder.
Cell AD5 is a date
Now, what I am wanting to do is go a step further and create a folder for the year "yyyy" and then the sub folder "mm-yyyy" for keeping things better organized.
So, I thought I could just edit the PATH line to:
But this results in an error: Run-time error '13': Type mismatch
I want the code to create the folder named for the year "yyyy" if it is not already created, and then create the sub-folder "mm-yyyy" if it is not already created also.
If the folder for year "yyyy" is already created then just create the sub-folder "mm-yyyy".
If both folders, "yyyy" and "mm-yyyy" are already there, then just go to FILENAME line and save the file in the corresponding folder
What am I forgetting here? Or what am i doing wrong?
VBA Code:
Sub MakeFolderAndSave()
Dim Path As String
Dim fldr As String
Dim filename As String
Path = "C:\Users\JD\Documents\Completed Time Sheets\" & Format(Range("AD5"), "mm-yyyy")
fldr = Dir(Path, vbDirectory)
If fldr = "" Then MkDir Path
filename = "LE " & Range("AK10").Value & " " & Format(Range("AD5").Value, "mm-dd-yyyy") & " - " & Range("A4").Value & " - " & Range("A6").Value
ThisWorkbook.SaveAs filename:=Path & "\" & filename
End Sub
Cell AD5 is a date
Now, what I am wanting to do is go a step further and create a folder for the year "yyyy" and then the sub folder "mm-yyyy" for keeping things better organized.
So, I thought I could just edit the PATH line to:
VBA Code:
Path = "C:\Users\JD\Documents\Completed Time Sheets\" & Format(Range("AD5"), "yyyy") \ Format(Range("AD5"), "mm-yyyy")
I want the code to create the folder named for the year "yyyy" if it is not already created, and then create the sub-folder "mm-yyyy" if it is not already created also.
If the folder for year "yyyy" is already created then just create the sub-folder "mm-yyyy".
If both folders, "yyyy" and "mm-yyyy" are already there, then just go to FILENAME line and save the file in the corresponding folder
What am I forgetting here? Or what am i doing wrong?