Forum Discussion
excelnoob298
May 03, 2020Copper Contributor
Creating a vba code so the file save in month folders
Hi guys Im having trouble with the final part of this vba code so i was hoping this community could help. im trying to create a vba that will save the file in month folders. Now my file save in year...
Subodh_Tiwari_sktneer
May 04, 2020Silver Contributor
You may try something like this...
Dim filename101 As String
Dim path101 As String
Dim fso As Object
Application.DisplayAlerts = False
Set fso = CreateObject("Scripting.FileSystemObject")
path101 = Environ("UserProfile") & "\Dropbox\A271\5 Oppgjør\" & Year(Date) & "\"
If Not fso.FolderExists(path101) Then
MsgBox "The folder " & path101 & " doesn't exist.", vbExclamation
Exit Sub
End If
filename101 = Range("B1").Value & ".xlsx"
ActiveWorkbook.SaveAs path101 & Range("A1").Value & "\" & filename101, xlOpenXMLWorkbook
Application.DisplayAlerts = Trueexcelnoob298
May 04, 2020Copper Contributor
Subodh_Tiwari_sktneer thanks for the code but its seems like the code dont want to run. its stops at Activeworkbook.saveas and dont run anymore.
1. I do have folder already created so the code for folder creating i dont think i need it. but it just stops working when the code comes to saving it dont do it.
2. Could please explain if that environ is something i have to copy to or remove it and why is the username in brackets? im new to this so im trying to learn.
3. Can you see if there is anything i can add on the code i wrote instead of writing all new? If its not possible to add anything then its no problem i can just go with that code.
Thanks